Answer the question
In order to leave comments, you need to log in
How to update a table with a complex condition?
There is a table with two fields: id, active
And there is a list of id (id_list) that do not need to be updated. How to update only those records in the table that do not fall into the id_list list, and which have active=1
I have come up with the following options so far:
1) I make a selection of the necessary elements, and then update them one by one.
$data = Model::find()->where(['not in', 'id', $id_list])->andWhere(['active' => 1])->all();
foreach($data as $line) {
// обновить элемент
}
Model::updateAll(['active' => 0], 'active = 1 AND id NOT IN ('.implode(',', $id_list).')');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question