cGridView can't get left join data

I’m performing a left join in a data query and can’t retrieve the left joined table data in a cGridView. I have two tables: Rant and Topic.

Here is the Rant class pertaining to the join:




	public function relations()

	{

		return array(

			'user' => array(self::BELONGS_TO, 'User', 'userId'),

			'topic' => array(self::BELONGS_TO, 'Topic', 'topicId'),

		);

	}



Here is the code that builds the sql query in the controller:




	public function actionIndex()

	{

		$criteria=new CDbCriteria(array(

			'with'=>'user',

			'with'=>'topic',

			'order'=>'topic.topicId desc',

			

		));

		

		$dataProvider=new CActiveDataProvider('Rant', array(

			'pagination'=>array(

				'pageSize'=>15,

			),

			'criteria'=>$criteria,

		));

		

		$this->render('index',array(

			'dataProvider'=>$dataProvider,

		));

	}



Here is the code in the view where I try to access the "Topic" tables data:




        array(            

            'name'=>'User',

			'type'=>'raw',

            'value'=>'($data->userId != 0) ? \'\' : "<a href=\"/site/index.php/user/$data->userId\">$topic->description</a>"',

        ),



I can access all the data from the “Rant” table, but I can’t get at the “Topic” table data. I did a “print_r” on the $data var and I can see that the join worked. How do I put the “Topic” data in the cGridView???

This should work




'with'=>array('user', 'topic'),



also keep this in mind (may be needed)




together=>true,



/Tommy

Thanks - that’s working to get the data, but how do I display the data from the “Topic” or “User” table? I’ve got this in my cGridView:




        array(            

            'name'=>'User',

			'type'=>'raw',

            'value'=>'($data->userId != 0) ? \'\' : "<a href=\"/site/index.php/user/$data->userId\">$data->description</a>"',

        ),



I get the following error:

Property "Rant.description" is not defined.

"description" is a column from the "Topic" table.

Use this syntax




$data->topic->description



/Tommy

I tried that and I get the following error:

Object of class Topic could not be converted to string

I read in another post that I need to be using innoDB tables. I’m using Myisam, but I do see the

Thanks Tommy! That works, although I also had to modify the cGridView to add a couple "." operators. This is what did the trick:




        array(            

            'name'=>'User',

			'type'=>'raw',

            'value'=>'($data->userId == 0) ? \'\' : "<a href=\"/site/index.php/user/$data->userId\">".$data->user->name."</a>"',

        ),