mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-2497: When trying to join single-table inheritance classes in DQL or QueryBuilder, Doctrine creates incorrect SQL #3132
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 @doctrinebot on GitHub (Jun 10, 2013).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user baohx2000:
When writing a DQL query joining to inherited subclasses, Doctrine incorrectly injects the discriminator in the WHERE clause instead of in the JOIN, where it should be.
Example: 2 classes extend Person via JOINED table inheritance: EmployedPerson and UnemployedPerson. I want to create a query where I pull separate class-specific properties form each class:
SELECT p FROM Person p
LEFT JOIN EmployedPerson ep WITH ep=p
LEFT JOIN UnemployedPerson up WITH up=p
The SQL from this will look something like:
SELECT .... FROM person p
LEFT JOIN person ep ON(ep.id=p.id)
LEFT JOIN person up ON(up.id=p.id)
WHERE ep.discrim IN('employed') AND up.discrim IN('unemployed')
The problem is this query will produce no results if one of the subclasses have no results.
The fix would be putting the discriminator in the JOIN so the sql would be:
SELECT .... FROM person p
LEFT JOIN person ep ON(ep.id=p.id AND ep.discrim IN('employed'))
LEFT JOIN person up ON(up.id=p.id AND up.discrim IN('unemployed'))
I will try to create a unit test based on the current ones and upload it.
@doctrinebot commented on GitHub (Jun 10, 2013):
Comment created by baohx2000:
Sorry, this is a duplicate of http://www.doctrine-project.org/jira/browse/DDC-2235
I don't see where to mark as dupe...
@doctrinebot commented on GitHub (Jun 11, 2013):
Comment created by @ocramius:
Duplicate of DDC-2235
@doctrinebot commented on GitHub (Jun 11, 2013):
Issue was closed with resolution "Duplicate"
@doctrinebot commented on GitHub (Aug 16, 2013):
Comment created by @doctrinebot:
A related Github Pull-Request [GH-656] was closed:
https://github.com/doctrine/doctrine2/pull/656
@doctrinebot commented on GitHub (Aug 16, 2013):
Comment created by @doctrinebot:
A related Github Pull-Request [GH-758] was closed:
https://github.com/doctrine/doctrine2/pull/758
@doctrinebot commented on GitHub (Aug 9, 2014):
Comment created by @doctrinebot:
A related Github Pull-Request [GH-656] was closed:
https://github.com/doctrine/dbal/pull/656
@doctrinebot commented on GitHub (Dec 26, 2014):
Comment created by @doctrinebot:
A related Github Pull-Request [GH-758] was assigned:
https://github.com/doctrine/dbal/pull/758
@doctrinebot commented on GitHub (Dec 27, 2014):
Comment created by @doctrinebot:
A related Github Pull-Request [GH-758] was closed:
https://github.com/doctrine/dbal/pull/758