Order by relations fields

Hi friends, i’m brazilian, sorry by my English.

I have the next relationship:

User.operation_id => Operation.id

I’m using the CActiveRecord:




class User extends CActiveRecord

{ .... 

    public function relations() {

        return array('operation' => array(self::BELONGS_TO, 'Operation', 'operation_id'));

    }

  ....

}



And I have the next search:




public function search() {

   $criteria = new CDbCriteria;

        

   $criteria->distinct = true;

   $criteria->compare('id', $this->id);

   $criteria->compare('operation_id', $this->operation_id, true);

   $criteria->compare('t.name', '~' . $this->name, true);

   $criteria->compare('email', $this->email, true);

   $criteria->compare('password', $this->password, true);

   $criteria->compare('t.status', $this->status, true);

   $criteria->compare('created_date', $this->created_date, true);

   $criteria->compare('last_login', $this->last_login, true);

                

   return new CActiveDataProvider(get_class($this), array('criteria' => $criteria));

}



… finaly the problem…

In the view page i have a CGridView, showing: User.name, User.loginName, User.Id, Operation.Name and others user attributes, all the attributes are ordened (clicking in the header), only the Operation.Name is not.

The problem is, I whant order the Grid by Operation.Name, how can i do it?

Please help!!!

try this:


$criteria->order('t.name desc');