2017-07-24 31 views
0

查詢結果將會是update table1 set id=id+1 where id>=10 and staff_id=$staff_idyii2 updateallcounter有2個條件

由於只有一個條件,我可以寫

\common\models\leave\table1::updateAllCounters(['id' => 1], ['>', 'id', 10]);

如何添加其中staff_id=$staff_id?試過\common\models\leave\table1::updateAllCounters(['id' => 1], ['>', 'id', 10],['staff_id'=>$staff_id]);卻無濟於事。

回答

4

,你可以像下面

$condition = ['and', 
    ['>', 'id', 10], 
    ['=', 'staff_id',$staff_id], 
]; 

創造條件,更新您的查詢

\common\models\leave\table1::updateAllCounters(['id' => 1],$condition);