I have 2 tables called Matchups and Teams. Matchups table contains two team id which are foreign keys of Teams table.
I considered creating a M:M relationship table such as matchup_team which would have the Matchup ID and Team ID.
That can give me the opportunity of binding more than 2 teams to a Matchup. But I know that I need exactly 2 teams to create a Matchup. So I think I should not choose that way.
These are the tables:
Teams Table:
'id' // primary key
'name' // name of the team
...
Matchups Table:
'id' // primary key
'user_id' // stores the creator of the matchup
'team1_id' // first team, foreign to Teams table
'team2_id' // second team, foreign to Teams table
...
On Matchup modal, I have:
public function team1()
{
return $this->belongsTo('App\Team');
}
public function team2()
{
return $this->belongsTo('App\Team');
}
So if I want to get the first team that is playing in a certain matchup, I can write:
\App\Matchup::find(1)->team1
The Problem:
What should I write in Team modal to reach which Matchup the team is in. Because there are 2 columns that can carry the Team information. team1_id or team2_id. I can change my table structure if you think somethings wrong there. I'm open to any suggestions. Thanks.