什么是“错误”?使用我的 DQL 查询?

发布于 2024-09-28 15:22:13 字数 1099 浏览 0 评论 0原文

我有以下 SQL 查询:

select bank.*
from bank
join branch on branch.bank_id = bank.id
join account a on a.branch_id = branch.id
join import i on a.import_id = i.id

它返回的正是我所期望的。

现在考虑以下两个 DQL 查询:

      $q = Doctrine_Query::create()
        ->select('Bank.*')
        ->from('Bank')
        ->leftJoin('Branch')
        ->leftJoin('Account')
        ->leftJoin('Import');

-

      $q = Doctrine_Query::create()
        ->select('Bank.*')
        ->from('Bank')
        ->innerJoin('Branch')
        ->innerJoin('Account')
        ->innerJoin('Import');

如果能够使用“join()”方法就好了,但是,从这里的官方 Doctrine 连接文档中可以看出,“DQL 支持两种连接 INNER JOIN 和左加入。”由于某种我完全无法理解的原因,他们选择不支持自然连接。无论如何,这意味着上面的两个查询是我唯一的选择。嗯,这很不幸,因为它们都不起作用

第一个查询(带有左连接的查询)不起作用,因为当然,左连接和自然连接是两个不同的东西。

第二个查询也不起作用。令人困惑的是,我收到一个错误:“未知的关系别名。”

为什么 Doctrine 能够找出 LEFT JOIN 的别名,但不能找出 INNER JOIN 的别名?

顺便说一句,我意识到 INNER JOIN 和 JOIN 只是名义上不同,但为什么要实现更具体的别名,不是规范的、自然的吗?

I have the following SQL query:

select bank.*
from bank
join branch on branch.bank_id = bank.id
join account a on a.branch_id = branch.id
join import i on a.import_id = i.id

It returns exactly what I expect.

Now consider the following two DQL queries:

      $q = Doctrine_Query::create()
        ->select('Bank.*')
        ->from('Bank')
        ->leftJoin('Branch')
        ->leftJoin('Account')
        ->leftJoin('Import');

-

      $q = Doctrine_Query::create()
        ->select('Bank.*')
        ->from('Bank')
        ->innerJoin('Branch')
        ->innerJoin('Account')
        ->innerJoin('Import');

It would have been nice to have been able to use a "join()" method but, from the official Doctrine join documentation here, it says, "DQL supports two kinds of joins INNER JOINs and LEFT JOINs." For some reason that thoroughly escapes me, they chose not to support natural joins. Anyway, what that means is that the two queries above are my only options. Well, that's unfortunate because neither of them work.

The first query - the one with left joins - doesn't work because, of course, a left join and a natural join are two different things.

The second query doesn't work, either. Bafflingly, I get an error: "Unknown relation alias."

Why should Doctrine be able to figure out the alias for a LEFT JOIN but not for an INNER JOIN?

By the way, I realize INNER JOIN and JOIN are only nominally different but why implement the more specific one and not the canonical, natural one?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不必在意 2024-10-05 15:22:13
    ->select('b.*')
    ->from('Bank b')
    ->leftJoin('b.Branch h')

    ->select('b.*')
    ->from('Bank b')
    ->innerJoin('b.Branch h')

http://www.doctrine -project.org/documentation/manual/1_1/en/dql-doctrine-query-language:join-syntax

    ->select('b.*')
    ->from('Bank b')
    ->leftJoin('b.Branch h')

    ->select('b.*')
    ->from('Bank b')
    ->innerJoin('b.Branch h')

http://www.doctrine-project.org/documentation/manual/1_1/en/dql-doctrine-query-language:join-syntax

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文