开发者

How do I model a table tennis match in rails

开发者 https://www.devze.com 2023-01-18 14:22 出处:网络
I am attempting to model a table tennis match in rails.Here is what I have: Game Model: team_1_score team_2_score

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_id

Team Model:

game_id

player_id

Player Model:

Name

So 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'
0

精彩评论

暂无评论...
验证码 换一张
取 消