Issue with Relational Active Record Sorting

Hello everybody !

I have the following table’s structure :

Sale

saleId

serviceId

createDate

Service

serviceId

clientId

Client

clientId

name

createDate

I wish I could sort by client.name and createDate(Sale’s column) in admin Sale’s view. I am expected to Disambiguating columns like createDate.




$criteria->order = 'sale.createDate, client.createDate';


$models=sale::model()->with(array("service"))->findAll($criteria);

Sale’s model


'service' => array(self::BELONGS_TO, 'service', 'serviceId', 'alias' =>'service', 'with' => array('client' => array('alias' => 'client'))),

Sale’s admin action


		$sort->attributes = array(

			'client.name' => 'clienteName',

			'createDate', // This one is sale createDate

			'serviceId', // serviceId defined in sale's table

			'comissao'

		);

I still getting this error :


CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'createdDate' in order clause is ambiguous

My query :

... LEFT OUTER JOINclientclient ON (service.clientId=client.clientId) WHERE (sale.deletedDate IS NULL) ORDER BY sale.createDate, client.createDate, sale.serviceId, service.serviceId, [b]createDate[/b],client.name` DESC LIMIT 10

How could I fix it ? Thank you

Hello again!

I have solved it by myself!




		$sort->attributes = array(

			'client.name' => 'clientName',

			'sale.createDate' => 'createDate',

			'sale.serviceId' => 'serviceId',

			'comissao'

		);






'service' => array(self::BELONGS_TO, 'service', 'serviceId', 'alias' =>'service', 'order'=>'??.serviceId', 'with' => array('client' => array('alias' => 'client', 'order'=>'??.createDate'))),



Hope help someone else ;)

Great!I had the same problem and still don’t find the answer for it.