Hello,
i’ve been searching around, but cannot find a suitable example or help how to access a property of a relations relation.
I’ve got the following structure:
Controller:
$model = Offer::model()->with('offerCategories')
->together()
->before(date('Y-m-d H:i:s'))
->after(date('Y-m-d H:i:s'))
->limit()
->recently()
->findAll(array(
'select' => 'id,title'
)
);
$dpLatestOffers = new CArrayDataProvider($model);
OfferModel:
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, 'User', 'user_id'),
'radius' => array(self::BELONGS_TO, 'Radius', 'radius_id'),
'offerCategories' => array(
self::HAS_MANY,
'OfferCategory',
'offer_id',
'with'=>array(
'category'=>array(
'select'=>'name'
)
),
'together'=>true,
),
'users' => array(self::MANY_MANY, 'User', 'user_rating(offer_id, user_id)'),
);
}
I want to access the property name in the category relation.
I tried this in my view:
'columns'=>array(
array(
'name'=>'name',
'header'=>Yii::t('general','Category'),
'value'=>'$data->offerCategories->category->name'
),
)
But i get only Trying to get property of non-object.
Can anyone help?