我很好奇我错过了什么。只有一个例子可以帮助解释,但首先是句子问题:Inventory 和 InventoryCategory - 两者都有图像关联。当我查看单个 InventoryCategory 和相关的 Inventory 时,我想要两个图像关联。目前我只返回了 InventoryCategory->Image。没有为库存项目返回任何图像。这就是我在模型中的内容:
Inventory:
public $belongsTo =
array(
'User'
, 'InventoryCategory'
,
);
public $hasMany =
array(
'Image' => array
(
'className' => 'Media.MediaImage'
, 'foreignKey' => 'foreign_key'
, 'conditions' => array(
'Image.model' => 'Inventory'
, 'Image.group' => 'Image'
,
)
, 'dependent' => true
, 'order' => 'Image.rank ASC, Image.id ASC'
)
,
);
public function containedModels()
{
$contain = array(
'Image'
, 'User'
, 'InventoryCategory'
,
);
return $contain;
}
InventoryCategory
public $hasOne =
array(
'Image' => array
(
'className' => 'Media.MediaImage'
, 'foreignKey' => 'foreign_key'
, 'conditions' => array(
'Image.model' => 'InventoryCategory'
, 'Image.group' => 'Image'
,
)
, 'dependent' => true
,
)
,
);
public $hasMany =
array(
'Inventory'
,
);
public function containedModels()
{
$contain = array(
'Image'
, 'Inventory'
,
);
return $contain;
}