CloudSeph
CloudSeph

Reputation: 883

Yii 2 Update All Not IN

Based on the code below, I want to update all in customer to status 1 where status = 2. However, i want to run the code below where customer_id not in (1, 3, 5, 8).

$customerNotIn = array(1, 3, 5 ,8);
Customer::updateAll(['status' => 1], 'status = 2');

How can i achieve that?

Upvotes: 3

Views: 4205

Answers (2)

Jay Prajapati
Jay Prajapati

Reputation: 1

Here is a correct answer

Customer::updateAll(['status' => 1], ['AND',['status'=>1],['NOT IN','customer_id',[1, 3, 5 ,8]]]);

[email protected]

Upvotes: 0

gmc
gmc

Reputation: 3990

The condition can be in the format of what you'd put in a ->where(), so in your case would be:

$customerNotIn = array(1, 3, 5 ,8);
Customer::updateAll(['status' => 1], ['AND', 
    'status = 2', 
    ['NOT IN', 'status', $customerNotIn]
]);

Upvotes: 7

Related Questions