There is a SQL query

DELETE FROM tbl_um_keys WHERE user_id = 6 AND module_id IN (20, 21, 31); 

How this request can be implemented using Yii2

  • Anyone else have any options - Xfirab

2 answers 2

Using ActiveRecord

 YourModel::deleteAll(['user_id' => 6, 'module_id' => [20, 21, 31]]); 

Or by means of Connection

 \Yii::$app->db->createCommand() ->delete('tbl_um_keys', ['user_id' => 6, 'module_id' => [20, 21, 31]]) ->execute() 

    Something like that

      $records=tbl_um_keys::find()->where(['user_id'=>6])->andWhere(['in','module_id',[20,21,31]])->all(); $records->delete(); 
    • Can not write Call to a member function delete() on a non-object - Xfirab