views:

39

answers:

1

Hi, I use CakePHP 1.2.6 and have the following relations:

Showcase HABTM User belongsTo Galleryitem hasOne Image

I try to get all the data related to a Showcase, and therefor also all its users with their Galleryitem -> Image. I use the following query:

$showcase = $this->Showcase->find('first',
    array('conditions'=>array('Showcase.id'=>$id),
        'contain'=> array(
            'User' => array(
                'Galleryitem' => array(
                    'Image'
                )
            )
        )
    )
);

This does returns and empty array of Galleryitem and thus no Image records at all. If I try the following:

$showcase = $this->Showcase->User->find('first',
    array(
        'contain'=> array(
            'Galleryitem' => array(
                'Image'
            )
        )
    )
);

I do get some data here about Image. So it seems the depth plays a role here.

Other factors that came to mind were the belongsTo relation between User and Galleryitem.

What causes my query not to return data from a depth of 3?

Update The set of Showcase relations is in my project much more branched than I explain above. All the other branches properply show up. So I guess it has to do with specific relations in this branch, the User belongsTo Galleryitem.

Strange still, because the other branches contain this very same set of Galleryitem hasOne Image relation.

+1  A: 

I usually go for the dot syntax (which I can't see in the book):

$this->Showcase->contain('User','User.GalleryItem','User.GalleryItem.Image');
$showcase = $this->Showcase->User->find('first');

although I'm struggling to find a three-deep example in any of my code.

Leo
This (albeit deprecated) post by Felix Geisendörfer dates back to the early days of containable and might help to explain: http://debuggable.com/posts/bringing-the-cold-war-to-cakephp-12-the-containable-behavior:480f4dd6-2b50-4d7b-ab05-418dcbdd56cb
Leo
+1, A.B.C is the only thing that works for me too for deeper relations.
sibidiba
Thanks! It seems my problem did reside in secondary code. After rewriting/cleaning up it worked.By the way: I found that a `fields` array in one branch about e.g. `Image` affects the other branches that contain an `Image` field. The last `fields` array dictates the others.
Brelsnok