Very new to Rails, have managed a few simple projects, but now stepping into more complex associations between tables and was hoping for some help.
The scenario can best be related to a sports match. Let’s say we have
1) A Team (has_many players)
2) A Player (belongs_to team)
3) A Match — now it gets tricky.
A Match will have: 2 teams, and 22 players (11 on each side) that take part in it. Also, associated with each player, will be their scores for the match (for example, Shots on goal, Goals scored, Points, etc.)
What would be the best practice to create this kind of association? Any tips would be greatly appreciated.
Models
app/models/team.rb
app/models/player.rb
app/models/match.rb
app/models/team_match.rb
app/models/player_match.rb
Migrations
db/migrate/create_matches.rb
db/migrate/create_players.rb
db/migrate/create_teams.rb
db/migrate/create_player_matches.rb
db/migrate/create_team_matches.rb
Edit1: @Mischa should share credit here! 🙂
Edit2: Sorry about the many versions, I totally underestimated this problem.