Sort On Calculated Column

Hello everybody

i am trying to sort my database data by a calculated column




		$dataProvider = new CActiveDataProvider('Entries', array(


			'criteria'=>array(

				'select' => 't.*, SUM(votes.value) AS test',

				'join' => 'join votes ON votes.type_id = t.id',

				'condition' => 'votes.type = 0',

				'group' => 't.id',

				

			),

			'pagination'=>array('pageSize' => 30,)

		));


		$this->render('index',array(

			'dataProvider'=>$dataProvider,

		));



in the view i have this:


<?php 





// $dataProvider->sort->defaultOrder='$entry->test DESC';

$data = $dataProvider->getData();


foreach ($data as $entry)

{




	echo $entry->test."<br />";




}




?>

But I always get this error message and i can’t figure out why:

Property "Entries.test" is not defined although it is in my select clause.

How am I able to sort my data on a calculated column?

Any help would be greatly appreciated.

did not have time to try coding, here is my idea:

  1. in your model define virtual property

public $test;

also add this property to your rule as normal property

  1. in your dataprovider [may not be necessarily, try it out]:

			

'sort'=>array(

	'attributes'=>array(

		'test'=>array(

			'asc'=>'test',

			'desc'=>'test DESC',

	),

	'*',

),



thank you very much, that fixed the problem :)