i try to sort and filter on a STAT relation inside the CGridView. But i’m stuck with this:
[font="Courier New"]CDbException
Description
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘total.total’ in ‘order clause’[/font]
model:
public $total;
public function relations() {
return array(
'rDaytrips' => array(self::MANY_MANY, 'Daytrip', 'daytrip_tag(tag_id, daytrip_id)'),
'tagCount' => array(self::STAT, 'Daytrip', 'daytrip_tag(tag_id, daytrip_id)'),
);
}
public function search() {
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria = new CDbCriteria;
$criteria->compare('id_tag', $this->id_tag);
$criteria->compare('tag', $this->tag, true);
$criteria->compare('tag', $this->total);
$criteria->with = array('tagCount');
return new CActiveDataProvider(get_class($this), array(
'criteria' => $criteria,
'pagination' => array(
'pageSize' => Yii::app()->params['itemsPerPage'],
),
'sort' => array(
'defaultOrder' => 'tag',
'attributes' => array(
'*',
'total' => array(
'asc' => 'total.total',
'desc' => 'total.total DESC',
)
)
),
));
}
view:
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'tag-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
'id_tag',
'tag',
array(
'name' => 'total',
'value' => '$data->tagCount',
),
array(
'class' => 'CButtonColumn',
'template' => '{update} {delete}',
),
),
));
?>