mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Specify ON column for leftJoin()
#6341
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @AntoniusGolly on GitHub (Nov 6, 2019).
I want to do a query like this
The point is, the LEFT JOIN is not done on the id columns of account and contact. I am aware of
WITHto specify further conditions. But in my case, I don't have further conditions to the join on id, but I only have the condition on join on email.It seems very obvious to do but I can't find the solution.
@SenseException commented on GitHub (Nov 11, 2019):
@AntoniusGolly Your query seems to fetch scalar values from the database. If these are the 4 columns/properties you try to fetch, why are you using DQL instead of SQL?
@AntoniusGolly commented on GitHub (Nov 12, 2019):
Sure, I can use SQL. Is the answer that this isn't possible in Doctrine?
@SenseException commented on GitHub (Nov 14, 2019):
An ORM is used to return objects of the data from the source database. In most cases you have no advantages when you use DQL to fetch scalar values. That's why I was asking why SQL was used.
https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#dql-select-examples
The arbitrary join is supposed to cover an use case similar to that. A DQL query like
could return results you're looking for, but as mentioned before, if you don't want to fetch the data in form of (entity) objects, you should use SQL if there's no other reason for DQL.
@piotrkardasz commented on GitHub (Nov 22, 2019):
It is possible. You can try native query to map entity
https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/native-sql.html#resultsetmappingbuilder