I am having an issue with Yii relations. I am using CGridView to display a table in a view.
I have the following relations in my model:
'relationName' => array(self::BELONGS_TO, OtherModelName, link_id),
When I call the value in my CGridView like the example below it works fine:
'relationName.field_name',
When I try to call the value inside an array like the example below:
array('header'=>'tableHeaderName', 'value'=>'$data->relationName->field_name'),
My page fails and I get the following error: Trying to get property of non-object
Any ideas or suggestions? Thanks so much for your help.
I’ve run into this recently myself. You’ll need something like this:
What happens is that Yii freaks out if the relation isn’t always there. So if you have any gaps in your data / relationships, then you run into problems.