holala
(Holala)
1
model employee:
public function relations()
{
return array(
'groups' => array(self::MANY_MANY, 'Group', 'groupemployee(group_id, employee_id)'),
}
table groupemployee have 3 fileds,there are: group_id,employee_id,ordering.
I want list employees with group_id=1 and order by ordering.
here is code in another controller action,but it don’t work,i don’t know why,please help me.
$dataProvider=new CActiveDataProvider('Employee', array(
'criteria'=>array(
'condition'=>'status = :status',
'params'=>array(':status'=>1),
'with'=>array(
array('groups'=>array('condition'=>'group_id = 1','order'=>'ordering'))
),
),
'pagination'=>array(
'pageSize'=>20,
),
));
thanks a lot!
cyberpol
(Cyberpol 777)
2
I don’t know if this work, but try this:
$dataProvider=new CActiveDataProvider('Employee', array(
'criteria'=>array(
'condition'=>'status = :status',
'params'=>array(':status'=>1),
'with'=>array(
array('groups'=>array('condition'=>'group_id = 1','order'=>'groupemployee.ordering')) //<<NOTE THAT LINE
),
),
'pagination'=>array(
'pageSize'=>20,
),
));
yoshi
(Jaschakoch)
3
Hi,
ehm, cause the relation is in your model employee you have to switch the key attributes - i think.
Instead of
public function relations()
{
return array(
'groups' => array(self::MANY_MANY, 'Group', 'groupemployee(group_id, employee_id)'),
}
try
public function relations()
{
return array(
'groups' => array(self::MANY_MANY, 'Group', 'groupemployee(employee_id,group_id)'),
}
regards
holala
(Holala)
4
thanks both of you!
i changed by your way,but still don’t work.
i changed code to:
$dataProvider=new CActiveDataProvider('Employee', array(
'criteria'=>array(
'condition'=>'status = :status',
'params'=>array(':status'=>1),
'join'=>'INNER JOIN groupemployee ON groupemployee.employee_id=id AND groupemployee.group_id='.$model->group_id,
'order'=>'groupemployee.ordering',
),
'pagination'=>array(
'pageSize'=>20,
),
));
it’s work.