Answer the question
In order to leave comments, you need to log in
Yii2 - how to make a double relation?
The task is this, there are 3 tables: articles, tags and articles_tags (link table) articles_tags
contains
3 columns:
- id
- article_id
-
tag_id
id=1) and it has 2 tags (tree (tag_id=1) and hollow (tag_id=2)), in the link table we will have 2 entries:
1 - 1 (tree tag for article 1)
1 - 2 (hollow tag for an article 1)
I need to get all the tags for my article, I wrote this getter:
public function getTags()
{
return $this->hasMany(ArticlesTags::className(), ['article_id' => 'article_id']);
}
Answer the question
In order to leave comments, you need to log in
In general, this is described in detail in the documentation.
See viaTable and via:
https://github.com/yiisoft/yii2/blob/master/docs/g...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question