3
我很好奇我錯過了什麼。只有一個例子可以幫助解釋,但這裏是第一個問題:Inventory和InventoryCategory - 都有圖像關聯。當我查看單個庫存類別和相關庫存時,我希望這兩個圖像關聯。目前我只返回InventoryCategory-> Image。沒有圖像爲庫存項目返回。這是我的模型:CakePHP - 擴展模型關聯
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;
}