I have these models
class Game < ActiveRecord::Base
belongs_to :home_team, :class_name => ‘Team’
belongs_to :away_team, :class_name => ‘Team’
belongs_to :field
end
class Person < ActiveRecord::Base
has_many :affiliations
has_many :teams, :through => :affiliations
end
class Team < ActiveRecord::Base
has_many :affiliations
has_many :players, :through => :affiliations, :source => :person
has_many :games
end
class Affiliation < ActiveRecord::Base
belongs_to :person
belongs_to :team
end
I with the associations above, I can get the players for the teams,
the home team and away team players from the games.
I want to be able to go back and get the games that each team and/or
player plays in. The associations work in one direction but not in the
other. How do I work back through the home_team and away_team
connections and get home games, away games and the totals for a given
player or team?
Any ideas?
Thanks
Andrew