I have being struggling with related model data for a while and can't seem to pin point the problem, I have been reduced to using a very simple example.
I have two models Dog and Owner, which have the following relations.
Owner:
public function getDogs()
{
return $this->hasMany(Dog::className(), ['owner_id' => 'id']);
}
Dog:
public function getOwner()
{
return $this->hasOne(Owner::className(), ['id' => 'owner_id']);
}
As a simple test I want to get the dog to disaply from the grid view in the index page in Owner view This is my index.php in the Owner view
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'name',
[
'attribute' => 'type',
'value' => 'dog.type',
],
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
I must be missing something fundamental here?
Getting unknown property: app\models\Owner::dogdog, since it'sdogs.dogtodogsand now the page loads, but not the value, it just says in the Type columnnot set->with('dogs')in your query?