Answer the question
In order to leave comments, you need to log in
hasManyToMany(viaTable) binding in yii2?
Model Film :
public function getActorName()
{
return $this->hasMany(Actor::className(), ['actor_id' => 'film_id'])
->viaTable('actor_film_mapping', ['actor_id' => 'film_id']);
}
Во вью :
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'actor_id',
'value' => 'actorName.name'
],
'film_id',
'name',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Answer the question
In order to leave comments, you need to log in
You have an idea in the actorName.name array. Here he is cursing.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question