Eager fetching does not return related data


I have a model ‘User’ that relates to it itself via created_user_id and updated_user_id.

  public function relations() {

    return array(

        'create_user' => array(self::BELONGS_TO, 'User', 'create_user_id'),

        'created_users' => array(self::HAS_MANY, 'User', 'create_user_id'),


        'update_user' => array(self::BELONGS_TO, 'User', 'update_user_id'),



In my controller I try to get the whole data to be used for a datagrid.

  protected function handleReadAction() {

    $pi = $this->getPagingInfo();

    $total = User::model()->count();

    $criteria = new CDbCriteria();


    $criteria->offset = $pi['start'];

    $criteria->limit = $pi['limit'];

    $criteria->order = 't.username ASC';

    $data = User::model()->findAll($criteria);

    return $this->ExportToJSONDataSource($data, $total);


$data does not contain the related data.

Any ideas?

Thanks in advance.

Daniel Khan

$criteria->together = true;

this one should do the trick.

I think this only changes the fetchtype but not the data to be fetched. At least I see no change.

did you try to output your query? maybe that will help.

I’m pretty new to Yii and only found niftly logging settings for doing this. Is there an easy way?

For the logging the following links should help:

Guide - Logging in Yii

API - Enable SQL Parameter logging