getting hasMany records of a HABTM relationship

Posted by charliefarley321 on Stack Overflow See other posts from Stack Overflow or by charliefarley321
Published on 2012-10-18T14:49:51Z Indexed on 2012/10/18 17:01 UTC
Read the original article Hit count: 268

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about cakephp