Alireza Fallah
Alireza Fallah

Reputation: 4607

Update a field by $model->updateAll in Yii

I want to execute this query :

update table_name where field=field+1

what I'm trying to do is :

$model->updateAll(array("field"=>"field+1"),"id = ".$id);

field is integer , and after that running this code it updates to 0 .

does this syntax is wrong for $model->updateAll ?

do I have to use another function ?

Upvotes: 1

Views: 1773

Answers (1)

Alireza Fallah
Alireza Fallah

Reputation: 4607

$model->updateAll can't do this , the correct function that I should use is:

$model->updateCounters(array("field"=>"1"),"id = ".$id);

Upvotes: 1

Related Questions