Hi,
I’ve been working with presenting data. I’m having a slight problem trying to sort the data with a related model column.
Here is my code, if anyone could point me in the right direction that would be great.
Controller
public function actionIndex($id)
{
$dataProvider=new CActiveDataProvider('Area', array(
'criteria' => array(
'with' =>'areaItems',
'condition' => 't.id=:area_id',
'params' => array(':area_id'=>$id)
),
'sort'=>array(
'attributes'=>array(
'title'=>array(
'asc'=>'title',
'desc'=>'title DESC'
),
'price'=>array(
'asc'=>'price',
'desc'=>'price DESC'
)
)
),
'pagination'=>array(
'pageSize'=>5,
)
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
My view
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'sortableAttributes'=>array(
'title', 'price'
),
));
My relations are:
'areaItems' => array(self::HAS_MANY, 'Item', 'area_id') // Area Model
'Area' => array(self::BELONGS_TO, 'Area', 'area_id') // Item Model
When I try to sort the results I get the following error: CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘title’ in ‘order clause’.
I should also mention that i’ve tried referencing the table directly and through the relation like areaItems.title but I still get the following error.
Thanks in advance for any solutions
Jonny