NCS_One
(Ncsantos Ncs)
1
Hi,
Model1.php
...
public function relations()
{
return array(
'Model3Count'=>array(self::STAT, 'Model3', 'id'),
);
}
...
Model2.php
...
public function relations()
{
return array(
'Model1Rel'=>array(self::BELONGS_TO, 'Model1', 'id'),
);
}
...
Now on a Controller.php
...
$model = Model2::model()->with('Model1Rel.Model3Count')->findAllByAttributes(...);
...
I need it ordered by Model3Count, how do I do it?
Thanks.
seenivasan
(Chellamnivas)
2
Dear Friend
Would you please try this.
1.Declare a virtual property in model2
public $model3count;
2.Do the following
$arr=array();
$models=model2::model()->findAll();
foreach($models as $model)
{
$model->model3count=$model->Model1Rel->Model3Count;
$arr[]=$model;
}
$dataProvider=new CArrayDataProvider($arr, //Not CActiveDataProvider
array(
'sort'=>array('attributes'=>array('Model3Count')),
'pagination'=>array('pageSize'=>10),
));
Use this $dataProvider in CListView or CGridView.
If you are using it in CListView dont fail to add Model3Count as sortableAttributes.
I hope it helps a bit.