Answer the question
In order to leave comments, you need to log in
How to do leftJoin() with two tables in yii2?
Here is a working query in sql:
SELECT * FROM `client`
LEFT JOIN `user` ON `client`.`client_id` = `user`.`id`
LEFT JOIN `company` ON `user`.`company_id` = `company`.`id`
$dataProvider = new ActiveDataProvider([
'query' => Client::find()
->leftJoin('user', 'client.client_id = user.id')
->leftJoin('company', 'user.company_id = company.id')
]);
Answer the question
In order to leave comments, you need to log in
Write the relations in the User model and you can write $query = User::find()-> joinWith ('client')->joinWith('company').
For such simple things, I think it will be enough (item "Working with connected data").
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question