Yii 2更新全部不在

时间:2017-04-14 03:12:22

标签: php yii yii2 yii2-model

根据以下代码,我想将所有客户更新为状态1,其中status = 2.但是,我想运行下面的代码,其中customer_id不在(1,3,5,8)中。

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

我如何实现这一目标?

1 个答案:

答案 0 :(得分:4)

条件可以采用->where()中的格式,因此在您的情况下将是:

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