Using counters with ActiveRecord

Comparing #3 with #4

Revision #4 was created by Alexander Ustimenko Alexander Ustimenko on Jul 16, 2012, 6:42:31 AM.

Adding 3rd problem -- updating in parallel by different user.

Content

[...]
$post->save();
$this->render('view', array('post' => $post));
}
```

We have t
wohree 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
[...]