次のコード行を使用して、特定の(無関係な)条件を持つすべての投稿をタグ「who」でフィルタリングしようとしています
$com= $this->Post->find('all', array('conditions' => $conditions, 'contain' => 'Tag.tag="who"'));
ただし、結果がタグ付きの投稿だけになるのではなく、タグ「who」を持たない投稿の空のタグ配列を持つすべての投稿を取得します。
私の質問が以前に出てきたことは知っていますが、投稿された解決策は私のコードでは機能しませんでした。ここのコードを自分のものに合わせてみました: http://web-development-blog.co.uk/2010/09/14/cakephp-habtm-find-with-conditions-and-containable-behavior/、しかし私はon 句に "Tag.post_id" が見つからないという SQL エラーが発生します。
助けてください。
選択したリンクからコードを実装しようとしたときのエラー メッセージ:
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')
));