当我将 findby($id) 与关联条件一起使用时,我收到 SQL 错误:1054

发布于 2024-12-22 00:46:35 字数 646 浏览 0 评论 0原文

我使用这个变量来查找与文章相关的评论。

 $comment = $this->Article->Comment->findAllById($id);

当我添加这样的条件时,我收到错误。

  $comment = $this->Article->Comment->findAllById($id,array('conditions' => array('Comment.status' => 1)));

我看到这个错误>>

Warning (512): SQL Error: 1054: Unknown column 'Comment.' in 'field list' [CORE\cake\libs\model\datasources\dbo_source.php, line 684]
Query: SELECT DISTINCT `Comment`.`` FROM `comments` AS `Comment` LEFT JOIN `articles` AS `Article` ON (`Comment`.`article_id` = `Article`.`id`) WHERE `Comment`.`id` = 15 

i use this variable to find the comments that related with articles..

 $comment = $this->Article->Comment->findAllById($id);

i get errors when i added conditons like this..

  $comment = $this->Article->Comment->findAllById($id,array('conditions' => array('Comment.status' => 1)));

i see this error>>

Warning (512): SQL Error: 1054: Unknown column 'Comment.' in 'field list' [CORE\cake\libs\model\datasources\dbo_source.php, line 684]
Query: SELECT DISTINCT `Comment`.`` FROM `comments` AS `Comment` LEFT JOIN `articles` AS `Article` ON (`Comment`.`article_id` = `Article`.`id`) WHERE `Comment`.`id` = 15 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

來不及說愛妳 2024-12-29 00:46:35

查看 findAllBy的手册field_name>() 方法。

您会注意到第二个参数是一个字段数组。

我建议使用 Cake 的标准查找方法,例如:

$comment = $this->Article->Comment->find('all', array(
  'conditions' => array(
    'Comment.id'     => $id,
    'Comment.status' => 1
  )
));

Take a look at the manual for the findAllBy<field_name>() method.

You'll notice the second parameter is an array of fields.

I would recommend using Cake's standard find method, something like:

$comment = $this->Article->Comment->find('all', array(
  'conditions' => array(
    'Comment.id'     => $id,
    'Comment.status' => 1
  )
));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文