Revision #4 has been created by Alexander Ustimenko on Jul 16, 2012, 6:42:31 AM with the memo:
Adding 3rd problem -- updating in parallel by different user.
« previous (#3) next (#5) »
Changes
Title
unchanged
Using counters with ActiveRecord
Category
unchanged
Tips
Yii version
unchanged
Tags
unchanged
activerecord, counters, savecounters, updatecounters
Content
changed
[...]
$post->save();
$this->render('view', array('post' => $post));
}
```
We have twohree problems with this approach. All we want is to update the visits column, but the entire record will be updated. Also, if we didn't pass the false argument to the save method, all the validation process will be executed.
Also if someone in parallel will update record from 4 to 5, we still save it as 5, as our version of post record have 4.
Since 1.1.8, the CActiveRecord class has a method that can help us with this task. It's the [CActiveRecord::saveCounters()] method and its usage is pretty simple:
```php[...]