Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii2: updateAll with multi conditions

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);
like image 206
Hett Avatar asked Sep 09 '15 10:09

Hett


1 Answers

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

like image 164
soju Avatar answered Nov 02 '22 14:11

soju