I have tables: categories HABTM sculptures hasMany images
from the CategoriesController#find() produces an array like so:
array(
'Category' => array(
'id' => '3',
'name' => 'Modern',
),
'Sculpture' => array(
(int) 0 => array(
'id' => '25',
'name' => 'Ami',
'material' => 'Bronze',
'CategoriesSculpture' => array(
'id' => '18',
'category_id' => '3',
'sculpture_id' => '25'
)
),
(int) 1 => array(
'id' => '26',
'name' => 'Charis',
'material' => 'Bronze',
'CategoriesSculpture' => array(
'id' => '19',
'category_id' => '3',
'sculpture_id' => '26'
)
)
)
)
I’d like to be able to get the images related to sculpture in the array as well if this is possible?
Use CakePHP’s Containable Behavior. After reading about it and following the instructions, your find should look something like this:
In your Category model, you need: