RailsCasts Pro episodes are now free!

Learn more or hide this

Sergey Alekseev's Profile

GitHub User: sergey-alekseev

Site: http://sergeyalekseev.by/

Comments by Sergey Alekseev

Avatar

Sorry, we can use .reset_counters:
Category.all.map(&:id).each { |id| Category.reset_counters(id, :products) }

Avatar

Specifying a counter cache will add it to that model’s list of readonly attributes using attr_readonly.

I think raw SQL within migration is the only option to update counter cache column.