I have 3 models (User
, Message
and Tag
) with the following relations:
User
hasManyMessage
Message
belongstoUser
Message
HABTMTag
Tag
HABTMMessage
If a User is logged in he might want to see all Message
tagged with something.
$messages = $this->Message->find('all', array(
'conditions' => array("Message.user_id" => $this->uid),
'contain' => array(
'Tag' => array(
'conditions' => array(
'Tag.id' => $activetag['Tag']['id']
)
)
));
However, this find will return ALL messages of that user. (Containable behaviour is included in both models)
array('Tag' = array(...))
– Jelmer