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.

Image of Stellar post

Check out Episode 1: How a Hackathon Project Became a Web3 Startup 🚀

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

👋 Kindness is contagious

Dive into this thoughtful article, cherished within the supportive DEV Community. Coders of every background are encouraged to share and grow our collective expertise.

A genuine "thank you" can brighten someone’s day—drop your appreciation in the comments below!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found value here? A quick thank you to the author makes a big difference.

Okay