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???