我有三个模型:项目、学生和投票。下面的代码就是它们之间的关系。在项目模型中:
public $hasMany = array('Student' => array(
'className' =>'Student',
'foreignKey'=>'project_id',
'order' => 'Student.studentName DESC',
),
'Vote' => array(
'className' =>'Vote',
'foreignKey'=>'project_id',
));
在学生模型中:
public $belongsTo = array(
'Project'=>array(
'className'=>'Project',
'foreignKey'=>'project_id'
));
在投票模型中:
public $belongsTo = array(
'Project'=>array(
'className' => 'Project',
'foreignKey' => 'id'
));
但是,当我调用此函数时(在项目模型中):
public function getApprovedProjects(){
$approvedProjects = $this->find('all', array('conditions'=>array(
'Project.approved' => 1)));
return $approvedProjects;
}
这是我得到的数据:
Array(
[0] => Array
(
[Project] => Array
(
[id] => 0
[projectName] => MyProject
[semester] => GAME
[description] => Test project
[imageLink] =>
[approved] => 1
)
[Student] => Array
(
)
[Vote] => Array
(
)
)
[1] => Array
(
[Project] => Array
(
[id] => 1
[projectName] => CRIA STUFF
[semester] => CRIA
[description] => Cria project
[imageLink] =>
[approved] => 1
)
[Student] => Array
(
)
[Vote] => Array
(
)
)
)
它没有找到与该项目相关的任何学生或选票,即使它们存在并且我认为它应该存在。知道发生了什么吗?