Yeah, there isn’t any data that is needed from that table and both the tournament_match and torunament_participant have a relation to the the player table.
So the relations are like so:
Tournament_Match and Tournament_Participant have a column tournament_id which is related to Tournament
Tournament_Match has two columns home_id and away_id which are related to Tournament_Participant and Player.
The Player table has holds the screenname which I am ultimately wanting to display on the page.
$model = Tournament::findModel($id);
//Am I wrong that both these should render the screen name from the player table with the relations below.
$model->tournamentMatch->home->player->screenname;
$model->tournamentMatch->away->player->screenname;
The models look like this
[code]
class Tournament
{
…
public function getTournamentMatches()
{
return $this->hasMany(TournamentMatch::className(), ['tournament_id' => 'id']);
}
}
class TournamentMatch
{
…
public function getAway()
{
return $this->hasOne(TournamentParticipant::className(), ['player_id' => 'away_id']);
}
public function getHome()
{
return $this->hasOne(TournamentParticipant::className(), ['player_id' => 'home_id']);
}
}
class TournamentParticipant
{
…
public function getPlayer()
{
return $this->hasOne(Player::className(), ['id' => 'player_id']);
}
}
Basically what I’m doing is from the TournamentController I am rendering the Bracket and
SELECT home
.screenname
as home_player
, away
.screenname
as away_player
, tm
.home_score
as home_score
, tm
.away_score
as away_score
, tm
.reported_at
as reported_at
From tournament_match
as tm
LEFT JOIN player
as home
ON tm
.home_id
= home
.id
LEFT JOIN player
as away
ON tm
.away_id
= away
.id
where tm
.tournament_id
= 1 AND tm
.status
= 2