widget CListView with Junctiun of tables

Hello,

After trying all day long to make it work, I couldn’t do it so I am finally asking for help… I am trying to use the Widget CListView in order to display the messages received by a user. I just have to link 2 tables (Message.FromUserId = User.UserId) and i want to display the following fields :

-Message.SentDate

-Message.Subject

-User.Username

In SiteController.php I have:




$dataProvider=new CActiveDataProvider(

                'Message', 

                array(

                    'criteria'=>array(

                        'with'=>'user',

                        'together' => true,

                        'condition'=>'t.ToUserId=' . Yii::app()->user->userId(),

                    ),

));


$this->render('message',array('dataProvider'=>$dataProvider,));

In Message.php :


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

	'dataProvider'=>$dataProvider,

	'itemView'=>'_view',

)); ?>

And in the view _view :


<tr>

    <td><?php echo CHtml::encode($data->Username); ?></td>

    <td><?php echo CHtml::encode($data->Subject); ?></td>

    <td><?php echo CHtml::encode($data->DateSent); ?></td>

</tr>

The error message i get is :

"Property "Message.Username" is not defined.

If i remove the line in the _view concerning the $data->Username , it works just fine, so i guess it might somehow be related to the LEFT JOIN… or that I missed something big as I just started with the framework… The error message is quite explicit but i really can’t get how to solve this problem so I would be very grateful if someone could help me with that.

Thank you in advance.

Still haven’t found what is the problem… any help would be great!

Thanks…!

try something like this:

on the 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(

		   .....

			'relationName' => array(self::BELONGS_TO, 'relatedtable', 'foreignkey'),

       	.....

		);

	}




on the controller:




...

with = array (

	'relationName' => array('column1', 'column2', 'column3'),

),

...



on the view:




....

<?php echo CHtml::encode($data->relationName->column1); ?>

....



Thanks for the help :)!