How to update all records by my condition? (my code is not work)
$condition[] = ['>', 'position', $old_position];
$condition[] = ['<=', 'position', $new_position];
$condition[] = ['in', 'id', $ids];
Video::updateAll([
'position' => new \yii\db\Expression('@a := @a + 1'),
], $condition);
You forgot the operator, you should simply try :
$condition = ['and',
['>', 'position', $old_position],
['<=', 'position', $new_position],
['in', 'id', $ids],
];
Read more : http://www.yiiframework.com/doc-2.0/yii-db-query.html#where()-detail
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With