简体   繁体   English

Medoo PHP框架和联接多个表

[英]Medoo PHP Framework and joining multiple tables

Trying to join 3 tables: leagues, leagues_teams, and teams. 尝试加入3个表:Leagues,Leagues_teams和team。

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 当添加第二个LEFT JOIN时 ,它应该与Leagues_teams.fifa_league_id = leagues.fifa_id而不是team.fifa_league_id一起加入

How would I go about this join? 我该如何加入?

In case someone was still having this problem, from MEDOO documentation: 如果有人仍然有此问题,请参阅MEDOO文档:

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 MEDOO-选择API

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM