2

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?

2mas
  • 127
  • 2
  • 14

1 Answers1

1

In case someone was still having this problem, from MEDOO documentation:

You can refer the previous joined table by adding the table name before the column.

Example:

"[>]album" => ["account.user_id" => "user_id"],

MEDOO - SELECT API

Shape
  • 64
  • 2