监护人型号:(关系)
'studentsGuardians' => array(self::HAS_MANY, 'StudentsGuardian', 'guardian_id'),
学生模型关系:
'studentsGuardians' => array(self::HAS_MANY, 'StudentsGuardian', 'student_id'),
学生监护人模型关系:
'guardian' => array(self::BELONGS_TO, 'Guardian', 'guardian_id'),
'student' => array(self::BELONGS_TO, 'Student', 'student_id'),
现在在控制器中,我想选择那些 Guardian_id=id 但我的代码选择所有记录而不过滤的学生。我的代码是
public function actionAssignGuardian($id)
{
$dataProvider = new CActiveDataProvider('Student',
array(
'criteria' => array(
'with'=>array('studentsGuardians',
array('criteria'=>
array('with'=>array('guardian','condition'=>' guardian_id=:id',
'params'=>array('id'=>$id))))),
),
));
$this->renderPartial('Pages/_assignGuardian', array(
'dataProvider' => $dataProvider,
'id'=>$id,
));
}
请指出我如何选择那些在功能中给定 id 的学生的正确方法。我是 yii 的新手。谢谢。