DDC-332: GROUP BY in Inheritance Scenario fails #410

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

Originally created by @doctrinebot on GitHub (Feb 14, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user @beberlei:

In an Inheritance Scenario the discriminator column is automatically added to the select columns, however Postgres and Oracle only allow columns in the select clause that are also in the group by clause.

The DQL Parser must detect this scenario and NOT add the descriminator column to the result if a grouping occours. In this case the descriminator would have to be added by the user explicitly. Example:

SELECT p.department, AVG(p.salary) AS avgSalary FROM Doctrine\Tests\Models\Company\CompanyEmployee p
GROUP BY p.department HAVING SUM(p.salary) > 200000
Originally created by @doctrinebot on GitHub (Feb 14, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user @beberlei: In an Inheritance Scenario the discriminator column is automatically added to the select columns, however Postgres and Oracle only allow columns in the select clause that are also in the group by clause. The DQL Parser must detect this scenario and NOT add the descriminator column to the result if a grouping occours. In this case the descriminator would have to be added by the user explicitly. Example: ``` SELECT p.department, AVG(p.salary) AS avgSalary FROM Doctrine\Tests\Models\Company\CompanyEmployee p GROUP BY p.department HAVING SUM(p.salary) > 200000 ```
admin added the Bug label 2026-01-22 12:37:27 +01:00
admin closed this issue 2026-01-22 12:37:28 +01:00
Author
Owner

@doctrinebot commented on GitHub (Feb 14, 2010):

Comment created by romanb:

The discriminator must always be added, but we can probably skip it if the hydration mode is not OBJECT.

When querying for objects, whether partial or full, the discriminator column must be added. If there is a grouping, it should probably be automatically added to the group by clause, not sure.

@doctrinebot commented on GitHub (Feb 14, 2010): Comment created by romanb: The discriminator must always be added, but we can probably skip it if the hydration mode is not OBJECT. When querying for objects, whether partial or full, the discriminator column **must** be added. If there is a grouping, it should probably be automatically added to the group by clause, not sure.
Author
Owner

@doctrinebot commented on GitHub (Feb 14, 2010):

Comment created by @beberlei:

i agree on skip discriminator if hydration mode is not object.

That would be solution for my case anyhow, since i did a scalar hydration. Object Hydration and GROUP BY hardly makes sense or not?

@doctrinebot commented on GitHub (Feb 14, 2010): Comment created by @beberlei: i agree on skip discriminator if hydration mode is not object. That would be solution for my case anyhow, since i did a scalar hydration. Object Hydration and GROUP BY hardly makes sense or not?
Author
Owner

@doctrinebot commented on GitHub (Feb 28, 2010):

Comment created by @beberlei:

This issue was fixed by the DQL Partial object syntax refactoring. Since p.department is not a partial object anymore the discriminator column is not added to the selection list anymore and the query doesnt fail anymore.

@doctrinebot commented on GitHub (Feb 28, 2010): Comment created by @beberlei: This issue was fixed by the DQL Partial object syntax refactoring. Since p.department is not a partial object anymore the discriminator column is not added to the selection list anymore and the query doesnt fail anymore.
Author
Owner

@doctrinebot commented on GitHub (Feb 28, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Feb 28, 2010): 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#410