我使用的是 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
关系。User
Galleryitem
是什么导致我的查询不返回深度为 3 的数据?
更新
Showcase 关系集在我的项目中比我上面解释的要分支得多。所有其他分支都正确显示。所以我想这与这个分支中的特定关系有关,User belongsTo Galleryitem
.
仍然很奇怪,因为其他分支包含这组完全相同的Galleryitem hasOne Image
关系。