Yii2 How to perform where AND or OR condition grouping?

后端 未结 8 2329
说谎
说谎 2020-12-08 02:02

I am new to Yii-2 framework. How can i achieve following query in Yii-2 framework using activeQuery and models.

SELECT * FROM users AS u WHERE u.user_id IN(1         


        
8条回答
  •  青春惊慌失措
    2020-12-08 02:37

    Use OR condition at first. For example:

    (new \yii\db\Query())
                ->select(['id', 'client', 'ts', 'action'])
                ->from('log_client as log')
                ->orWhere(['action' => 'lock'])
                ->orWhere(['action' => 'rel'])
                ->andWhere(['in', 'client', $IDs])
                ->orderBy(['ts' => SORT_ASC])
                ->all();
    

    It'll be like a "AND...(..OR..)"

提交回复
热议问题