How to display hasMany relationship in Yii?

Hello! Tell me how to remove the link table using the staging table? There are 3 tables with a relationship: 'judge', 'judge-comitet', 'comitet'

You need to bring to the table 'judge' a comma has committees in the staging table to the 'judge-comitet', ( something like this: implode(', ', $judgeComitets->category->name ));

Model Judge

public function getJudgeComitets()
 return $this->hasMany(JudgeComitet::className(), ['judge_id' => 'id']);

Model JudgeComitet

public function getComitet()
 return $this->hasOne(Comitet::className(), ['id' => 'comitet_id']);
June 14th 19 at 18:54
1 answer
June 14th 19 at 18:56
return $this->hasMany(Tag::className(), ['id'=> 'tag_id'])
 ->viaTable('article_tag', ['article_id' => 'id']);
! I've done it before, but now I can't remember how to do this complex relationship. Could You write more detail what to do in the model and in the GridViews. Sitting blunt... And let it stay here, not to ask more of these stupid questions..) - jacquelyn_Nikolaus84 commented on June 14th 19 at 18:59
in models judje and comitet list the link that I mentioned above.

viaTable('article_tag', ['article_id' => 'id']); this method allows to link models through the intermediate table 'judge-comitet'. - brain commented on June 14th 19 at 19:02 - brain commented on June 14th 19 at 19:05
I roughly understand how it works. But still something does not work.

Model Judge and Comitet
public function getComitetName() {
 return $this->hasMany(Comitet::className(), ['id'=> 'judge_id'])
 ->viaTable('judge-comitet', ['comitet_id' => 'id']);

GridView Judge

 'label' => 'Category',
 'value' => function () {
 return implode(', ', ArrayHelper::map(\backend\models\Judge::find()->all(), 'id', 'comitetName'));

59da42fd4e018422650229.png - jacquelyn_Nikolaus84 commented on June 14th 19 at 19:08

Find more questions by tags Yii