Answer the question
In order to leave comments, you need to log in
How to set up a relation in Yii2 through a third table?
There are three models: Ts, Plans, Students
Is it possible to implement something like this?
Ts.php:
public function getPlans()
{
return $this->hasMany(Plans::className(), ['subject_id' => 'subject_id','teacher_id' => 'teacher_id', 'student.studyform_id' => 'studyform_id']);
}
Answer the question
In order to leave comments, you need to log in
So there is an example in the documentation, linking through a table:
www.yiiframework.com/doc-2.0/guide-db-active-recor...
Hi, I did something similar, I stored post_id and tag_id in the linked table, here I
wrote in the model responsible for Posts
public function getTags()
{
return $this->hasMany(Tags::className(), ['id' => 'tag_id'])->viaTable('{{%statjiblogtags}}', ['post_id' => 'id']);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question