DEV Community

Igor Alexandrov for JetRockets

Posted on

3 3

Rails: increment counter cache and return value

What will you do if you have to in/decrement counter cache column and get it actual value via single query?. Learn how to hack ActiveRecord to do this in easy and pretty cool way.

http://jetrockets.pro/blog/rails-increment-counter-cache-and-return-value

Top comments (4)

Collapse
 
dsalahutdinov profile image
Dmitry Salahutdinov

Hi Igor, do you consider to create simple gem and make the common patch ?

Collapse
 
igor_alexandrov profile image
Igor Alexandrov
Collapse
 
igor_alexandrov profile image
Igor Alexandrov

I will update description and add specs later.

Collapse
 
igor_alexandrov profile image
Igor Alexandrov

Sure, give me a couple of days.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more