根据下面的代码,我想将 customer 中的所有内容更新为状态 1,其中 status = 2。但是,我想运行下面的代码,其中 customer_id 不在 (1, 3, 5, 8) 中。
$customerNotIn = array(1, 3, 5 ,8);
Customer::updateAll(['status' => 1], 'status = 2');
我怎样才能做到这一点?
条件可以采用您在
->where()
中输入的格式,因此在您的情况下将是:
$customerNotIn = array(1, 3, 5 ,8);
Customer::updateAll(['status' => 1], ['AND',
'status = 2',
['NOT IN', 'status', $customerNotIn]
]);
这是正确答案
Customer::updateAll(['status' => 1], ['AND',['status'=>1],['NOT IN','customer_id',[1, 3, 5 ,8]]]);