Use different names for the associations like :home_game and :away_game
Does this look right? It doesn't seem to work.
What do you mean by doesn't work?
It seems counter intuitive that a game would have many home/away
teams, I would expect
game belongs_to :away_team and game belongs to home_team, and then
team has_many away_games, team has_many home_games
but if this is the way your data really is then I can't argue with that
Fred.
Frederick Cheung wrote:
Does this look right? It doesn't seem to work.
What do you mean by doesn't work? It seems counter intuitive that a game would have many home/away teams, I would expect game belongs_to :away_team and game belongs to home_team, and then team has_many away_games, team has_many home_games but if this is the way your data really is then I can't argue with
thatFred.
I see what you're saying. I guess to me the games are more important than the teams, so I may have structured it backwards. I'll mess around with it and see what happens. Thanks!
It's just a question of what the relationships are. In most sports I
know of, a game will involve a home team and a away team, and over
the course of a season a team will play many away games and many team
games. from that your game table pretty much has to have a home team
id and an away team id, which leads to
class Game < AR:Base belongs_to :away_team, ... belongs_to :home_team, ... end
class Team < AR:Base has_many :home_games, ... has_many :away_games, ... end
Fred