简体   繁体   中英

Increment field in Yii using updateAll()

Good day! How to using updateAll() to make all records increment field on one?

Players::model()->updateAll(array('contract' => 5), 'contract < 5'); 

How do contract = contract + 1 , not 'contract' => 5 ?

There http://www.yiiframework.com/doc/api/1.1/CActiveRecord#saveCounters-detail , but it is only for one record.

$model->updateAll() can't do this, you should do this:

$model->updateCounters(array("contract"=>"1"),"contract < 5");

this, increments contract field on one, in every record that contract < 5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM