Hi all,
I have 2 tables, Department and Employees with a one to many relation between them defined in the following way:-
Department model:
return array(
'employees' => array(self::HAS_MANY, 'Employee', 'departmentId'),
);
Employee model:
return array(
'department' => array(self::BELONGS_TO, 'Department', 'departmentId'),
);
In one of the department views, I am listing the employees for that specific department.
I was using CActiveDataProvider to get the employees of the department. I was till now using the following code:
$dataProvider=new CActiveDataProvider('Employee',array(
'criteria'=>(array(
'condition'=>"departmentId=$model->id",//$model is an instance of the department
)
)
));
I just realised that I was not making use of the relation existing between the 2 tables and can instead use the following code:
$dataProvider = new CArrayDataProvider($results=$model->employees);
I want to be sure that I am not wrong. Can anybody confirm that this code always works in any similar situation?
Thanks