这个问题一直在抨击我的脑袋几天。当我在我的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