DDC-141: DQL with WHERE queries on Single Table Inheritance Entities fail #175

Closed
opened 2026-01-22 12:29:37 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 13, 2009).

Jira issue originally created by user nicokaiser:

The ORM query builder seems to be broken for Single Table Inheritance with discriminator.

When using inheritance like here:
http://www.doctrine-project.org/documentation/manual/2_0/en/inheritance-mapping#single-table-inheritance

Queries with WHERE fail:

SELECT p FROM MyProject\Model\Person p WHERE p.id = 1

This translates to this SQL:

SELECT p0*.id AS id0, p0_.discr AS discr1 FROM person p0_ WHERE p0_.id = 1 p0*.discr IN ('', 'person', 'employee')

(AND is missing after p0_.id = 1)

Originally created by @doctrinebot on GitHub (Nov 13, 2009). Jira issue originally created by user nicokaiser: The ORM query builder seems to be broken for Single Table Inheritance with discriminator. When using inheritance like here: http://www.doctrine-project.org/documentation/manual/2_0/en/inheritance-mapping#single-table-inheritance Queries with WHERE fail: `SELECT p FROM MyProject\Model\Person p WHERE p.id = 1` This translates to this SQL: `SELECT p0*.id AS id0, p0_.discr AS discr1 FROM person p0_ WHERE p0_.id = 1 p0*.discr IN ('', 'person', 'employee')` (AND is missing after p0_.id = 1)
admin added the Bug label 2026-01-22 12:29:37 +01:00
admin closed this issue 2026-01-22 12:29:38 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 13, 2009):

Comment created by romanb:

Thanks for reporting this. I'm just wondering where the empty string in the IN clause comes from? I dont seem to be able to reproduce that bit.

@doctrinebot commented on GitHub (Nov 13, 2009): Comment created by romanb: Thanks for reporting this. I'm just wondering where the empty string in the IN clause comes from? I dont seem to be able to reproduce that bit.
Author
Owner

@doctrinebot commented on GitHub (Nov 13, 2009):

Comment created by nicokaiser:

Argh, ignore the empty string, it is

SELECT p0*.id AS id0, p0_.discr AS discr1 FROM person p0_ WHERE p0_.id = 1 p0*.discr IN ('person', 'employee')

My initial example was a superclass that did not appear in the DiscriminatorMap...

@doctrinebot commented on GitHub (Nov 13, 2009): Comment created by nicokaiser: Argh, ignore the empty string, it is `SELECT p0*.id AS id0, p0_.discr AS discr1 FROM person p0_ WHERE p0_.id = 1 p0*.discr IN ('person', 'employee')` My initial example was a superclass that did not appear in the DiscriminatorMap...
Author
Owner

@doctrinebot commented on GitHub (Nov 13, 2009):

Comment created by romanb:

OK. Should be fixed now. Was a very trivial mistake. Now its covered in the tests.

@doctrinebot commented on GitHub (Nov 13, 2009): Comment created by romanb: OK. Should be fixed now. Was a very trivial mistake. Now its covered in the tests.
Author
Owner

@doctrinebot commented on GitHub (Nov 13, 2009):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Nov 13, 2009): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#175