yii2 ActiveQuery 'OR LIKE' filter

后端 未结 1 676
误落风尘
误落风尘 2021-01-07 17:48

i have a task - add to search model searching by full name. Full name is first name + last name. So i need to build query like

WHERE first_name LIKE \'%var%\         


        
相关标签:
1条回答
  • 2021-01-07 18:15

    You should simply try :

    $query->andFilterWhere([
        'or',
        ['like', 'profiles.first_name', $this->userFullName],
        ['like', 'profiles.last_name', $this->userFullName],
    ]);
    

    or: similar to the and operator except that the operands are concatenated using OR. For example, ['or', ['type' => [7, 8, 9]], ['id' => [1, 2, 3]] will generate (type IN (7, 8, 9) OR (id IN (1, 2, 3))).

    Read more : http://www.yiiframework.com/doc-2.0/yii-db-queryinterface.html#where()-detail

    0 讨论(0)
提交回复
热议问题