這個問題一直在抨擊我的腦袋幾天。當我在我的Department模型上執行find('all')時,不會獲取關聯的數據。這裏是我係車型:cakePHP相關數據沒有檢索
<?php
App::uses('AppModel', 'Model');
class Department extends AppModel {
public $displayField = 'name';
//The Associations below have been created with all possible keys, those that are not needed can be removed
public $belongsTo = array(///check
'District' => array(
'className' => 'District',
'foreignKey' => 'district_id'
)
);
public $hasMany = array(
'Group' => array(
'className' => 'Group',
'foreignKey' => 'department_id' ///check
),
'Request'=>array(
'className' => 'Request',
'foreignKey' => 'department_id',
),
'DepartmentPosition'=>array(
'className'=>'DepartmentPosition',
'foreignKey'=>'department_id',
'dependent'=>true
),
);
}
當我發現(「全部」),它返回的所有字段從數據庫中的每一個部門,但沒有相關的數據都沒有。在各部門的控制器:
$departments = $this->Department->find('all');
$this->set(compact('departments'));
感覺就像,因爲我沒有問題,與任何其他車型,並返回相關的數據,包括其相關的i系在模型的一個問題。例如,我可以找到與某個區有關的所有部門。
在此先感謝!
你可以張貼發現的所有參數()。 –
是的,在這一點上沒有。我只是在這裏做find('all'),然後在視圖中進行調試($ departments)。謝謝@Danial – Todd