0

I'm just doing my first steps with Laravel and web development in general. For this step of my project I'm designing DB for tournament website.

What I eventually need: Every match has 3 maps. Every map has own score for each team (score_left_team -Map_name - score right team ). And every match has general score (left_team_score - right_team_score) Perfect example: https://overwatchleague.com/en-us/match/10223

How can I create the correct relationships and improve my design below?

Team::
 id
 name

Player:: 
 id
 team_id (belongsTo Team::class)
 name

Map:: 
 id
 name
 photo

Match_Map:: 
 id
 map_id (belongsTo Map::class)
 match_id (belongsTo Match::class)
 score_left
 score_right

 Match:: 
  id
  date
  stage_name
  group_name
  left_team_id (belongsTo Team::class)
  right_team_id (belongsTo Team::class)
  score_left
  score_right
  winner (How to create here relationship?)
  status 

I appreciate any tips!

halfer
  • 19,824
  • 17
  • 99
  • 186

1 Answers1

0

Looks fairly correct, if you have the scores for both teams when you are creating the record, you could have a winner_id be a foreign key for a team id. This could be both on match_map and on match. Besides that looks good.

Alex Harris
  • 6,172
  • 2
  • 32
  • 57
  • Can you please explain a bit more about winners. Still don't get how to create a relationship. Ideally it should take values from 'left_team_id' and ' right_team_id' like so I can choose one of two match teams as winner. I'm not familiar what exactly foreign key mean. Thank you! – Philipp Kishkovarov Feb 22 '18 at 20:24
  • So left_team_id is a foreign key referring to the team tables id column. If you know the score before you make the record you can determine which team has the winning score. `winner_id` would also refer to the team table column id. – Alex Harris Feb 23 '18 at 17:41
  • I see, but I won't know the score before I make a record, that was the biggest issue that I don't understand how to solve. Maybe I will just leave a varchar for winner value and will add team_id manually, once I get the score. – Philipp Kishkovarov Feb 26 '18 at 16:47