M
M
Maxim2017-10-08 16:32:24
Yii
Maxim, 2017-10-08 16:32:24

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'
59da27930a52a168823624.png
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']);
    }

Model JudgeComitet
public function getComitet()
    {
        return $this->hasOne(Comitet::className(), ['id' => 'comitet_id']);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Borutkin, 2017-10-08
@myks92

return $this->hasMany(Tag::className(), ['id'=> 'tag_id'])
           ->viaTable('article_tag', ['article_id' => 'id']);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question