Yii2: updateAll with several conditions

How to update all records according to my condition? (my code is not working)

$condition[] = ['>', 'position', $old_position];
$condition[] = ['<=', 'position', $new_position];
$condition[] = ['in', 'id', $ids];

Video::updateAll([
    'position' => new \yii\db\Expression('@a := @a + 1'),
], $condition);
+9
source share
1 answer

You forgot the operator, just try:

$condition = ['and',
    ['>', 'position', $old_position],
    ['<=', 'position', $new_position],
    ['in', 'id', $ids],
];

More details: http://www.yiiframework.com/doc-2.0/yii-db-query.html#where()-detail

+19
source

Source: https://habr.com/ru/post/1606576/


All Articles