调试工具包显示重复查询

jhkqcmku  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(363)

我做了一个蛋糕toutorial,当我结束的时候,我查看了debugkitsql日志,在文章的编辑页面中,看起来检索文章数据的查询由于某种原因被复制了。
这是显示两次的查询:

SELECT 
  Articles.id AS `Articles__id`, 
  Articles.user_id AS `Articles__user_id`, 
  Articles.title AS `Articles__title`, 
  Articles.slug AS `Articles__slug`, 
  Articles.body AS `Articles__body`, 
  Articles.published AS `Articles__published`, 
  Articles.created AS `Articles__created`, 
  Articles.modified AS `Articles__modified` 
FROM 
  articles Articles 
WHERE 
  Articles.slug = 'first-post' 
LIMIT 
  1

这是编辑功能:

public function edit($slug)
    {
        $article = $this->Articles
            ->findBySlug($slug)
            ->contain('Tags') // load associated Tags
            ->firstOrFail();

        if ($this->request->is(['post', 'put'])) {
            $this->Articles->patchEntity($article, $this->request->getData(), [
                // Added: Disable modification of user_id.
                'accessibleFields' => ['user_id' => false]
            ]);
            if ($this->Articles->save($article)) {
                $this->Flash->success(__('Your article has been updated.'));
                return $this->redirect(['action' => 'index']);
            }
            $this->Flash->error(__('Unable to update your article.'));
        }
        $tags = $this->Articles->Tags->find('list');

        $this->set('article', $article);
        $this->set('tags', $tags);

    }

查询只能在此行执行一次:

$article = $this->Articles
            ->findBySlug($slug)
            ->contain('Tags') // load associated Tags
            ->firstOrFail();

对的?

vlju58qv

vlju58qv1#

有可能,debugkit被加载了两次。请参见bootstrap.php配置文件中的。如果有,请删除它,因为在3.6中加载的是application.php

相关问题