Answer the question
In order to leave comments, you need to log in
How to output hasMany relationship in Yii?
Hello! Tell me how to display a connection in a table through an intermediate table? There are 3 tables with a relationship: 'judge', 'judge-comitet', 'comitet'
It is necessary to output to the 'judge' table, separated by commas, the assigned committees in the intermediate table 'judge-comitet', (like this: implode(', ', $ judgeComitets->category->name ));
Judge Model
public function getJudgeComitets()
{
return $this->hasMany(JudgeComitet::className(), ['judge_id' => 'id']);
}
public function getComitet()
{
return $this->hasOne(Comitet::className(), ['id' => 'comitet_id']);
}
Answer the question
In order to leave comments, you need to log in
return $this->hasMany(Tag::className(), ['id'=> 'tag_id'])
->viaTable('article_tag', ['article_id' => 'id']);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question