beginner
beginner

Reputation: 2032

yii2 updateallcounter with 2 conditions

The query would be update table1 set id=id+1 where id>=10 and staff_id=$staff_id.

With only single condition I can write

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

How to add the where staff_id=$staff_id? Tried \common\models\leave\table1::updateAllCounters(['id' => 1], ['>', 'id', 10],['staff_id'=>$staff_id]); but no avail.

Upvotes: 0

Views: 647

Answers (1)

jithin
jithin

Reputation: 920

you can create conditions like below

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

and update your query

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

Upvotes: 4

Related Questions