尝试加入 3 个表:leagues、leagues_teams 和 teams。
使用查询:
$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'
]
);
这导致以下查询:
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
添加第二个LEFT JOIN时,它应该加入leagues_teams.fifa_league_id=leagues.fifa_id而不是teams.fifa_league_id
我将如何处理这个加入?