The SQL Alternative To Counter Caches
Eric Anderson

Hi Eric,

Very interesting read. I totally agree that for many cases the SQL alternatives benefits outweigh the performance cost.

I’m trying to use this solution wih cancancan and I’m stumbling with issues that the counts aren’t loaded in the object returned by the query.


@author = Author.with_counts.find_by id: params[:id]

raises a NoMethodError (undefined method books_count’…

Do you have any experience with this?

Like what you read? Give Barak Peleg a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.