Reputation: 4634
I have come up with two options to relate teams and games in my database; which one is most appropriate?
I was trying to make it simple, here is what I want. Teams
have many games
, and each game
has a home team
and an away team
. It's a many to many relationship.
Here is what I thought:
I am not sure whether I should put a boolean
field called ishome
in competes
table or add two fields called home_id
and away_id
, and set them as foreign
key to references team.id
like in following picture.
Upvotes: 2
Views: 857
Reputation: 204854
If you have always 2 teams playing against each other you can use
competes table
--------------
home_team_id
away_team_id
game_id
like in your 2nd option. But if you have a dynamic number of teams in a game then use the other.
Upvotes: 1