M
M
McMike2018-07-11 09:20:47
Yii
McMike, 2018-07-11 09:20:47

How to search by field concatenation in Yii2?

There is a request to select users by the full name of the form firstname || ' ' || lastname LIKE '%First Name%
' the first name is stored in two firstname-surname fields.
How to make such a query using builder in Yii2? This option swears
->orFilterWhere(['like', 'firstname || \' \' || lastname', $text]);
column \"firstname || ' ' || lastname\" does not exist

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mykola, 2018-07-11
@iSensetivity

->addSelect(['*', CONCAT('firstname', 'lastname') as full_name])->andFilterWhere(['like', 'full_name', $text])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question