M
M
mitaichik2016-03-18 16:56:36
Yii
mitaichik, 2016-03-18 16:56:36

How to write conditions in with/joinWith?

Hello! I recently moved to yii2 and have a question about the conditions in with, more precisely, about adding aliases:
Here is the code:

User::find()
            ->with(['address' => function(ActiveQuery $addressQuery){
                $addressQuery->where(['status' => 1]);
            }])
            ->where(['status' => 1])
            ->all();

I thought that since the nested $addressQuery is associated with the 'address' relay, it will add an alias/table to the 'status' field, that is, "address.status" will go into the request, but this does not happen.
Also in the main query, it would be logical that he himself would add an alias/table to the condition, that is, "user.status" would be included in the query. At least yii1 has this behavior.
Am I doing something wrong or is it supposed to be like this?
And if this is how it should be, is there a way in yii2 to make it add the table alias/name itself?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2016-03-19
@bitver

https://github.com/yiisoft/yii2/pull/10817
In general, there are a lot of answers to this question on the net.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question