RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: sergey-alekseev
Site: http://sergeyalekseev.by/
Sorry, we can use .reset_counters: Category.all.map(&:id).each { |id| Category.reset_counters(id, :products) }
Category.all.map(&:id).each { |id| Category.reset_counters(id, :products) }
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.
Sorry, we can use .reset_counters:
Category.all.map(&:id).each { |id| Category.reset_counters(id, :products) }
I think raw SQL within migration is the only option to update counter cache column.