我正在尝试使用以下代码行通过标签“谁”过滤所有具有某些(不相关)条件的帖子
$com= $this->Post->find('all', array('conditions' => $conditions, 'contain' => 'Tag.tag="who"'));
但是,结果不是只有带有标签的帖子,而是每个帖子都带有空标签数组,用于那些没有标签“谁”的帖子。
我知道我的问题之前已经提出,但发布的解决方案不适用于我的代码。我已经尝试将这里的代码调整为我自己的代码: http ://web-development-blog.co.uk/2010/09/14/cakephp-habtm-find-with-conditions-and-containable-behavior/ ,但我得到一条 SQL 错误,指出在 on 子句中找不到“Tag.post_id”。
请帮忙。
尝试从所选链接实现代码时出现错误消息:
SELECT `Post`.`id`, `Post`.`title`, `Post`.`body`, `Post`.`created`, `Post`.`modified`, `Tag`.`id`, `Tag`.`tag`, `Tag`.`created`, `Tag`.`modified` FROM `posts` AS `Post` LEFT JOIN `tags` AS `Tag` ON (`Tag`.`post_id` = `Post`.`id`) WHERE `Tag`.`tag` = 'who' 1054: Unknown column 'Tag.post_id' in 'on clause'
这是由使用这个引起的:
$this->Post->bindModel(array('hasOne' => array('Tag')));
$this->Post->contain(array(
'Tag'
));
$com=$this->Post->find('all', array(
'conditions'=>array('Tag.tag'=>'who')
));