I am looking for a great way to update the cache counter of this model.
Here is my model:
class GameParticipation < ActiveRecord::Base
belongs_to :game, counter_cache: true
end
AND:
class Game < ActiveRecord::Base
has_many :game_participations
end
Isn't that better than repeating on every element, such as the following code?
Game.pluck(:id).map{|g_id| Game.reset_counters(g_id, :game_participations) }
(I use Rails4 and activerecord)
source
share