我使用此变量来查找与文章相关的评论..
$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
答案 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
)
));