The SQL Alternative To Counter Caches
Eric Anderson
137

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.

E.g.

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

raises a NoMethodError (undefined method books_count’…

Do you have any experience with this?

Show your support

Clapping shows how much you appreciated Barak Peleg’s story.