I am trying to create a has_many through relationship with multiple sources.
For example, a game has home_team and away_team , and there are several games in the tournament.
What is the best way to get all the teams in a tournament using the has_many relation through games.
Now my code is as follows:
class Tournament has_many :teams, :through => :games, :source => :home_team, :uniq => true end
but I want him to do this:
class Tournament has_many :teams, :through => :games, :source => [:home_team, :away_team], :uniq => true end
EDIT: the relationship of many, many is not my problem. Is there a good way to get all the teams in a tournament, assuming the structure as follows.
class Game has_and_belongs_to_many :tournaments belongs_to :home_team, :class_name => Team, :foreign_key => :home_team_id belongs_to :away_team, :class_name => Team, :foreign_key => :away_team_id end class Tournament has_and_belongs_to_many :games end
Is there any way to make Tournament.teams ?
Josh wilson
source share