I'm a little bit confused about how Yii2 attributes work. If I have two tables (say tradition, culture) with a one-to-many relationship (i.e. one tradition could be present in several cultures) I could use Gii generated code and get in model Tradition something like @property Culture $culture, so I could use (in Tradition view index):
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'traditionname',
'culture.culturename',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
But what about a many-to-many relationship as in tables tradition, book, aux_tradition_book? Gii would automagically generate a @property Book[] $books, but how to use such an array inside a GridView in order to display a bunch of books referring to the same tradition?
Thanks for any help.
You can modify gii to do this or you can just modify the resulting file with something like this for many to many relations. Display results while joining tables in yii2
Make sure you set up eager loading and not lazyloading as it will make your page very slow.