I tried to find this everywhere but I cant. Here is my problem:
Lets say I have models associated like this:
When I use membershipsController
to send all membership to the view, I get only for example $membership['Membership']['id']
or $membership['TeacherCourse']['id']
BUT NOT $membership['TeacherCourse']['Teacher']['id']
...
Which means I get info on Memberships and TeacherCourse because they are directly associated. My question is how can I also get info about Teachers or Courses directly?
You could increase the model's recursion level to obtain deeper associations (set $this->Membership->recursive
to 2 or 3), but in general it's better to use the Containable
behavior so you can choose which associations you want to retrieve. For example this would return memberships with associated TeacherCourse and Teacher models:
$membership = $this->Membership->find('all', array(
'contain'=>array(
'TeacherCourse'=>array(
'Teacher'=>array()
),
));
See also the full documentation of the Containable behavior at http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html