0

我使用的是 CakePHP 1.2.6 并且有以下关系:

展示 HABTM 用户属于图库项目 hasOne Image

我尝试获取与 Showcase 相关的所有数据,因此也获取其所有用户及其 Galleryitem -> Image。我使用以下查询:

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

这确实返回和空数组,Galleryitem因此根本没有Image记录。如果我尝试以下操作:

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

我确实在这里得到了一些关于Image. 因此,深度似乎在这里发挥了作用。

想到的其他因素是和之间的belongsTo关系。UserGalleryitem

是什么导致我的查询不返回深度为 3 的数据?

更新 Showcase 关系集在我的项目中比我上面解释的要分支得多。所有其他分支都正确显示。所以我想这与这个分支中的特定关系有关,User belongsTo Galleryitem.

仍然很奇怪,因为其他分支包含这组完全相同的Galleryitem hasOne Image关系。

4

1 回答 1

2

我通常使用点语法(我在书中看不到):

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

尽管我很难在我的任何代码中找到一个三深的例子。

于 2010-07-19T15:22:40.190 回答