Answer the question
In order to leave comments, you need to log in
How to split an expression in a query into an array in Yii2?
There is a long query
(new Query())->select(...)->from(tab1)->leftJoin('tab2', 'tab1.a = tab2.a AND condition1 AND condition2 AND condition3')
Is it possible here is 'tab1.a = tab2.a AND condition1 AND condition2 AND condition3' split into an array like for example with where condition? I try everything, it gives an error.
Answer the question
In order to leave comments, you need to log in
https://www.yiiframework.com/doc/api/2.0/yii-db-qu...
Note that the array format of where() is designed to match columns to values instead of columns to columns, so the following would not work as expected:
['post.author_id' => 'user.id'], it would match the post.author_id column value against the string 'user.id'.
'post.author_id = user.id'
Try like this:
(new Query())
->select(['A.*', 'B.*'])
->from(['A' => MyClass::tableName()])
->leftJoin(['B' => JoinClass::tableName()], ['A.a' => new Expression('B.b')])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question