【发布时间】:2014-11-05 16:48:01
【问题描述】:
我正在寻找一种漂亮的方法来更新给定模型的计数器缓存。
这是我的模型:
class GameParticipation < ActiveRecord::Base
belongs_to :game, counter_cache: true
end
还有:
class Game < ActiveRecord::Base
has_many :game_participations
end
这不是比像下面的代码那样对每个元素进行迭代更好吗?
Game.ids.each {|id| Game.reset_counters(id, :game_participations) }
【问题讨论】:
标签: ruby-on-rails activerecord