My model has a few counters on it, and I want to increment/decrement these counters, and they should be done in a transaction.
So for example, the User model has sales_count, friend_count.
Now I want to modify both of them in a transaction:
user.sales_count += 1
user.friend_count += 3
user.save
How can I do this in a transaction?
I know there is increment_counter, but that seems to be for only a single attribute and I can’t figure out how to add 2 or subtract 2 instead of just 1.
you could use
update_counters