I have the following find function:
$this->MyModel->find('all', array('conditions' => array('id' => $id)));
which returns an array of this form
Array
(
[Model1] => Array
(
[Model1] => Array
(
...
...
)
)
[Model2] => Array
(
[0] => Array
(
...
...
)
[1] => Array
(
...
...
)
[2] => Array
(
...
...
)
...
...
...
)
)
How do I alter the the find all to limit how many elements the second model are fetched (Model2)?
I can add conditions => array( 'limit' => 10 ) but that limits the number of elements of the outer array – not Model2 i.e. the second nested array!
Any ideas? Thank you :).
You should use cake’s containable behaviour here to limiting the records of your second model. Here’s what you can do using containable to achieve this.
Now you will get maximum of 10 records from Model2.