When I try to sort by aliasA it gives the me error: [error] [system.db.CDbCommand] CDbCommand::fetchAll() failed: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘t.aliasA’ in ‘order clause’.
Looking at the debug message from the log yii has generated the following order by ORDER BY t.aliasA
I pasted the sql in phpmyadmin and kept failing until I changed the order by to ORDER BY aliasA (without the t alias for the table) and it worked perfectly.
Is there a workaround this or a way to tell yii not to put t. infront of the order by field?
$count=Yii::app()->db->createCommand('SELECT COUNT(*) FROM '.tName::model()->tableName().')->queryScalar();
$sql='SELECT id1+id2 as aliasA FROM '.tName::model()->tableName();//apply all your criteria to this query
$dataProvider=new CSqlDataProvider($sql, array(
'totalItemCount'=>$count,
'sort'=>array(
'attributes'=>array('aliasA'),
'defaultOrder'=>'id ASC',
),
'pagination'=>array(
'pageSize'=>self::PAGE_SIZE,
),
));
Thanks for your reply. The first approach is not working. The CSqlDataProvider approach seems to not throw the error when I attempt to sort but I am unable to render the value of the aliases through $data->someValue when I render the dataProvider in my view. I wonder if I am missing anything?