M
M
Maxim Timofeev2015-08-28 19:31:49
Yii
Maxim Timofeev, 2015-08-28 19:31:49

How to get array via hasMany relationship?

There are 3 tables users, companies, user role in the company, companies
Accordingly, there are connections:
users->hasMany user role in the company
user role in the company -> hasOne company
It is necessary to select companies for a specific user.
I can't figure out how to do it right.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Timofeev, 2015-08-28
@webinar

And the casket just opened

$array = $this->hasMany(Имя первой связиe::className(), ['user_id' => 'id'])->all();
        return ArrayHelper::getColumn($array,'имя второй связи');

Still, beer sometimes helps.

P
pantsarny, 2015-08-31
@pantsarny

MANY TO MANY, the viaTable method will help you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question