Getting all the associated tags for every item after a filterby(tag)
I have the typical association HABTM Item <-> Tag
If i get all the Items with tag= "test" doing this:
$items = $this->Item->Tag->find('all', array('conditions'=>array('Tag.name'=>$tag)开发者_如何学Python));
The $items array shows correctly the [Items] array containing the Items associated with the tag, but How can i get also all the Tags for every item, so I can show after the item and all his tags ?
Thank you.
Edit: Seems like Cake didn't like the idea. You can hack it by calling the association a little differently:
$this->Item->bindModel(array('hasAndBelongsToMany' => array( 'BlahTag'=>array( 'className' => 'Tag', 'joinTable' => 'items_tags', 'foreignKey' => 'item_id', 'associationForeignKey' => 'tag_id', 'unique' => true, ) )),false); $this->Item->BlahTag->bindModel(array('hasAndBelongsToMany' => array( 'Item'=>array( 'className' => 'Item', 'joinTable' => 'items_tags', 'foreignKey' => 'tag_id', 'associationForeignKey' => 'item_id', 'unique' => true, ) )),false);
$items = $this->Item->BlahTag->find('all', array(
'contain'=>array('Item'=>array('BlahTag')),
'conditions'=>array('BlahTag.name'=>$tag)
));
精彩评论