What's "wrong" with my DQL query?
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')
-开发者_Go百科>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?
->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
精彩评论