0
在查看InventoryCategory摘要時,我可以獲取庫存但不包括InventoryImages。 CakePHP報告的錯誤是[Model「Inventory」與模型「InventoryImage」]沒有關聯。這是我採用的型號:CakePHP模型擴展關聯
class InventoryCategory extends InventoriesAppModel {
public $hasMany =
array(
'Inventory'
, 'InventoryCategoryImage' => array
(
'className' => 'Media.MediaImage'
, 'foreignKey' => 'foreign_key'
, 'conditions' => array(
'InventoryCategoryImage.model' => 'InventoryCategoryImage'
, 'InventoryCategoryImage.group' => 'Inventory Category Image'
,
)
, 'dependent' => true
,
)
,
);
public function containedModels()
{
$contain = array(
'Inventory'
, 'InventoryCategoryImage'
,
);
return $contain;
}
}
class Inventory extends InventoriesAppModel {
public $belongsTo =
array(
'User'
, 'InventoryCategory'
,
);
public $hasMany =
array(
'InventoryImage' => array
(
'className' => 'Media.MediaImage'
, 'foreignKey' => 'foreign_key'
, 'conditions' => array(
'InventoryImage.model' => 'InventoryImage'
, 'InventoryImage.group' => 'Inventory Image'
,
)
, 'dependent' => true
, 'order' => 'InventoryImage.rank ASC, InventoryImage.id ASC'
)
,
);
public function containedModels()
{
$contain = array(
'User'
, 'InventoryCategory'
,
);
return $contain;
}
}
在你發現' '遞歸'=> 2'()調用?另外,請發佈給您的錯誤查找電話。 – Costa 2012-03-13 04:33:37
不,我不使用遞歸。包含而不是。 – radarhill 2012-03-14 14:33:44
'code'public功能視圖() { 如果 { \t $這 - >重定向($這 - >引薦())($這 - > PARAMS [ 'ID']!); } $條件\t =(is_numeric($ this-> params ['id'])) \t \t \t? array($ this-> modelClass。'.id ='=> $ this-> params ['id']) \t \t \t:array($ this-> modelClass。'.slug ='=> $ this-> params ['id']); $項\t \t = $這 - > {$這 - > modelClass} - >查找( \t \t \t '第一' \t \t \t,陣列( \t \t \t \t '條件' \t => $條件 \t \t \t \t, '包含' \t => $這 - > {$這 - > modelClass} - > containedModels() \t \t \t) \t); $ this-> set(compact('item')); '代碼' – radarhill 2012-03-14 14:36:25