Trying to join 3 tables: leagues, leagues_teams, and teams.
With the query:
$teams = $database->select(
'teams',
[
'[>]leagues_teams' =>
[
'fifa_id' => 'fifa_team_id'
],
'[>]leagues' =>
[
'fifa_league_id' => 'fifa_id'
]
], [
'teams.fifa_id',
'teams.name',
'teams.rating'
], [
'ORDER' => 'teams.name ASC'
]
);
Which results in the following query:
SELECT "teams"."fifa_id","teams"."name","teams"."rating"
FROM "teams"
LEFT JOIN "leagues_teams" ON "teams"."fifa_id" = "leagues_teams"."fifa_team_id"
LEFT JOIN "leagues" ON "teams"."fifa_league_id" = "leagues"."fifa_id"
ORDER BY "teams"."name" ASC
When adding the second LEFT JOIN, it should join with leagues_teams.fifa_league_id=leagues.fifa_id and not teams.fifa_league_id
How would I go about this join?