如何根据我的条件更新所有记录? (我的代码不起作用)
$condition[] = ['>','position',$old_position]; $condition[] = ['<=',$new_position]; $condition[] = ['in','id',$ids]; Video::updateAll([ 'position' => new \yii\db\Expression('@a := @a + 1'),],$condition);
你忘记了运算符,你应该试试:
$condition = ['and',['>',$old_position],['<=',$new_position],['in',$ids],];
阅读更多 :
http://www.yiiframework.com/doc-2.0/yii-db-query.html#where()-detail