A
A
Alexander Nevsky2018-11-16 15:36:06
Yii
Alexander Nevsky, 2018-11-16 15:36:06

How to link 3 yii2 tables?

5beeb8115b743059995100.png5beeb81e44e00350323451.png5beeb82c2c566913098799.png
There are 3 tables, you need to connect them, as I understand it, they need to be connected with the 4th table
5beeb8863840d483651173.png
. But I can’t figure out how to do this in terms of code. I registered everything in the tables, I generated the model for the 4th table through gii, but I don’t understand further ((

public function getBooks()
{
    return $this->hasOne(Books::className(), ['id' => 'books_id']);
}

public function getReview()
{
    return $this->hasOne(Reviews::className(), ['id' => 'review_id']);
}

public function getUser()
{
    return $this->hasOne(User::className(), ['id' => 'user_id']);
}

I need all this to display normally Reviews in certain books and display Nicky, those who wrote.
If there is another option for linking tables, I will not mind redoing everything)))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Arman, 2018-11-16
@Arik

If you do not want to store identifiers in the tables themselves, then you need to use intermediate tables , in your mind you should have a separate table for each connection then.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question