Jump to content

The ultimate community for Ruby on Rails developers.


Photo

counter_cache for has_many :through relationship

relationships

  • Please log in to reply
No replies to this topic

#1 sb89

sb89

    Passenger

  • Members
  • 1 posts

Posted 21 March 2014 - 10:15 PM

I'm having a bit of trouble in terms of what I should add to my models and migrations to create a counter_cache for a has_many :through relationship. Here are my models:
 
Game.rb
has_many :patches
has_many :tactic_revisions, :through => :patches
 
Patch.rb
belongs_to :game, counter_cache: true
has_many :tactic_revisions
 
Tactic.rb
has_many :tactic_revisions
 
TacticRevision.rb
belongs_to :tactic, counter_cache: true
belongs_to :patch, counter_cache: true
 
I'm trying to use a counter_cache to store how many TacticRevisions a Game has but unsure how to go about this. Any ideas?






Also tagged with one or more of these keywords: relationships

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users