当我使用带有关联条件的findby($ id)时,我得到SQL错误:1054

时间:2011-12-17 08:26:23

标签: cakephp cakephp-1.3 cakephp-appmodel

我使用此变量来查找与文章相关的评论..

 $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 

1 个答案:

答案 0 :(得分:2)

查看manual for the findAllBy<field_name>()方法。

您会注意到第二个参数是fields的数组。

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

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