I am attempting to model a table tennis match in rails. Here is what I have:
Game Model:
team_1_score team_2_score team_1_id team_2_idTeam Model:
game_id player_idPlayer Model:
NameSo each game will consist of 2 teams (of either 1 or 2 players each).
Then I was planning on linking game to player with has_many, :through. I don't think this will work because of the 2 instances of team in each game. But I really don't know 开发者_开发问答where I should go from here. Any help would be greatly appreciated.I'm not sure how to do the has_many :through between players and games, but it might be easier if you start out with something like this:
Team Model
id
name
has_many :players
has_many :games
Player Model
id
name
team_id
has_one :team
Then the Games model would have something like (in addition to what you already have):
has_one :team1, :class_name => 'Team'
has_one :team2, :class_name => 'Team'
精彩评论