When I try:
// Removed the limit to ensure that all of the group notes items can be found and collapsed
$recent_notes = $this->User->Note->find('all', array(
'recursive' => 2,
'order' => 'Note.created DESC',
'conditions' => $conditions,
'contains' => array(
'NotesUser', 'Poster', 'Comment' => array('Poster')
)
));
It does not limit the output whatsoever - I get every related model. However, when I don't specify recursive as 2, or if I specify it as 1, I am missing the Comment=>Poster model.
How can I get only the models I need? Thanks!
To get only the models you need, use the [Containable behavior]:
'contain' singular, NOT 'contains' plural, like you have$actsAs variable in your model: public $actsAs = array('Containable');Everyone that I know sets $this->recursive = -1; in the AppModel... this defaults everything to recursive -1 so you don't ever have to set it again unless you want to include more data...and in those cases, I almost always use contain(), not $recursive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With