Yii 2 更新全部未包含

问题描述 投票:0回答:2

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

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

我怎样才能做到这一点?

php yii yii2 yii2-model
2个回答
7
投票

条件可以采用您在

->where()
中输入的格式,因此在您的情况下将是:

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

0
投票

这是正确答案

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

[email protected]

© www.soinside.com 2019 - 2024. All rights reserved.