2

尝试加入 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

我将如何处理这个加入?

4

1 回答 1

1

如果有人仍然遇到此问题,请参阅 MEDOO 文档:

您可以通过在列前添加表名来引用以前的连接表。

例子:

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

MEDOO - 选择 API

于 2015-06-15T13:40:04.497 回答