Flowdock

Notes posted by gerry3

RSS feed
November 5, 2013
0 thanks

The "instance-level equivalent" ActiveRecord::Base#increment is NOT atomic

Typically, you want to increment counters atomically, so the class method ActiveRecord::Base.increment_counter is the right choice.

Also, there is an issue with the increment example below as it does not save automatically:

item = Item.find(1)
item.foo_count # => 0
item.increment(:foo_count)
item.foo_count # => 1
item.reload
item.foo_count # => 0
item.increment(:foo_count)
item.save
item.reload
item.foo_count # => 1