Reference Table Value Not Displayed In Yii Gridview

Hi

I am trying to display reference table value in CGridView but it doesn’t seems to be working. I have tried all possibility i found on internet.

Here is the relation. each user have multiple images and each image has single user.

UserImages.php model


public function relations()

{

    // NOTE: you may need to adjust the relation name and the related

    // class name for the relations automatically generated below.

    return array(

        'user'=>array(self::BELONGS_TO,'Users','user_id')

    );

}

Users.php Model


public function relations()


{


    // NOTE: you may need to adjust the relation name and the related


    // class name for the relations automatically generated below.


        return array(

            'images'=>array(self::HAS_MANY,'UserImages','user_id')

        );

}

User image grid view


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


'id'=>'user-images-grid',


'dataProvider'=>$model->search(),


'filter'=>$model,


'columns'=>array(


    'image_id',


    'user_id',


    array('name'=>'username', 'value'=>'$data->user->username', 'header'=>'User Name'),


    array('name'=>'filename','type'=>'raw','value'=>array($this,'gridThumb')),




    'caption',


    array(

        'class'=>'CButtonColumn',

        'template'=>'{update} | {delete}',

        'updateButtonImageUrl'=>false,

        'deleteButtonImageUrl'=>false,          

    ),

),


));

But every time i got this error: Property "UserImages.username" is not defined.

Is there anything wrong i am doing ? please help.

Note : both table contains user_id column

That tells your models UserImages don’t have any username attribute.

Check the Your UserImages models. If any upper case and lower case problem.

I think this is not username that is users.

Yes UserImages has no "username" field, but i have setup relation with Users model which contains "username" field. and i want to display Users model username value based on matching user_id


    array('name'=>'username', 'value'=>'$data->user->username', 'header'=>'User Name'),