How to do batchUpdate in yii2
14,010
Solution 1
Use updateAll() on your model.
Customer::updateAll(['status' => 1], 'status = 2');
From Yii 2 documentation
Hope it helps!
Solution 2
Please try this
Yii::$app->db->createCommand()
->update(self::tableName(),
[ 'field1'=>$value1 ], //columns and values
[ 'field2'=>$value2, 'field3'=>$value3 ]) //condition, similar to where()
->execute();
Solution 3
There are some facts.
At first here there is no batchUpdates, but batchInsert is exist.
At second, one man from Yii core said on russian forum that there is no batchUpdate in Yii2 Query builder cause it is too specific to implement it for various DB-systems.
Author by
sapo
Updated on June 25, 2022Comments
-
sapo about 2 years
Only batchInsert is available in yii2,
bacthUpdate
is not available in yii2, how can we do this in yii2 like CodeigniterbatchUpdate
? -
sapo about 9 yearsellislab.com/codeigniter/user-guide/database/…
batchUpdate
is there inCodeigniter
, please see the above link. I too can't find thebatchUpdate
in Yii2. Thanks for your info.