Gridview : order problem on foreign key name


I just discovered that my working yii application has this problem :

I have Planningledger table which has a "Belong to" relation with the table Employee

Problem is that I display Planningledger gridview and I have it ordered correctly by Emmployee Name

But when I’m clicking on the column header to order by Employee name it orders by the Employee id (foreign key)

Here’s what I have in Planningledger model :

function rules :

array('employee.fullname, id, date, employee_id, description, activity_id, solde', 'safe', 'on'=>'search'),

function relations :

'employee' => array(self::BELONGS_TO, 'Employee', 'employee_id'),

function search() :

$criteria = new CDbCriteria;

$criteria->with = array( 'activity','employee' );










$criteria->compare('employee.fullname',$this->employee->fullname, true);

$criteria->together = true;

$sort = new CSort();

$sort->attributes = array(



		'desc'=>'employee.fullname desc',




		'desc'=>' desc',



return new CActiveDataProvider($this, array(


		'pageSize'=> Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']),





		'defaultOrder'=>'employee.fullname ASC',



And this is part of my view :

<?php $this->widget('zii.widgets.grid.CGridView', array(






			'header' => Yii::t('app','model.planningledger.employee'),


			'value'=>'($data->employee_id === null) ? \' \' : $data->employee->fullname',

			'filter'=>CHtml::listData(Employee::model()->findAll(array('condition'=>'enabled=true', 'order'=>'fullname ASC')), 'id', 'fullname'),


All the other stuff (dropdownlist, searching, sorting on date) works fine.

But as I’m not displaying the id but the name I really must find the mistake I made.

I already read many posts but I can’t get it work.

You can not add ‘sort’ twice to the array, you should only add it once.

The second definition of ‘sort’=> overrides the previous one.

Further, I recommend the use of my "RelatedSearchBehavior" Extension: .

You can define ‘fullname’ as a “virtual” related attribute and sorting will be taken care of automatically. ‘CGridView’ will not really notice that it is a virtual attribute.

Check out the demo of the extension!

Oups - I did not see THIS - thanks a lot !

I will have a look too to your extension …