Closed GabeStah closed 9 years ago
counter_cache is actually the proper solution.
Using custom_counter_cache gem.
For characters#index
Raid counter:
Ensure :raids
association to Character
is unique and define :raids_count
counter_cache.
class Character < ActiveRecord::Base
has_many :raids, -> {uniq}, through: :participations, dependent: :delete_all
define_counter_cache :raids_count do |character|
character.raids.count
end
end
Since association is through Participation
, add update_counter_cache
call:
class Participation < ActiveRecord::Base
update_counter_cache :character, :raids_count
end
Fixed by 4a12709d48e35375943c3bdc8463d5a764bfeb6c
https://github.com/activerecord-hackery/squeel