可容忍的行为不会从深度3返回 - CakePHP

时间:2010-07-19 14:57:52

标签: cakephp recursion cakephp-1.2 belongs-to containable

我使用CakePHP 1.2.6并具有以下关系:

展示HABTM用户所属的Galleryitem拥有一个图像

我尝试获取与Showcase相关的所有数据,因此其所有用户都使用他们的Galleryitem - >图片。我使用以下查询:

$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的数据。因此,深度似乎在这里发挥作用。

我想到的其他因素是belongsToUser之间的Galleryitem关系。

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

更新 展示关系的集合在我的项目中比我上面解释的更加分支。所有其他分支都适当地显示出来。所以我想这与这个分支中的特定关系有关,User belongsTo Galleryitem

奇怪的是,因为其他分支包含同一组Galleryitem hasOne Image关系。

1 个答案:

答案 0 :(得分:2)

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

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

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