mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
Using DTOs with groups #6284
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 @core23 on GitHub (Aug 19, 2019).
Originally assigned to: @core23 on GitHub.
Bug Report
Summary
Since Version 2.4, it is possible to create queries with DTO result objects using
NEWoperator. Unfortunately it is not possible to use field aliases with this.Current behavior
There is a
RuntimeException:How to reproduce
I use the https://github.com/beberlei/DoctrineExtensions library for
MONTH,YEAR,COUNTandSUMsupport, but this should not be related to the actual problem.Create the following query:
Expected behavior
I can use aliases in the select method and reuse them later when creating groups.
@lcobucci commented on GitHub (Aug 19, 2019):
@core23 I'd say that it would be more logical to have an alias for the entire DTO and use its properties. Like:
However, this creates complexity for an edge-case that I'm not sure that it makes sense to add to the ORM - depending on which level we take this it might create a much more complicated query than what's needed.
Why don't you use the code below instead?
@core23 commented on GitHub (Aug 19, 2019):
Thanks for your response @lcobucci
I already tried your solution, but this produces a different
QueryException:I also trired using groups without an aggregate function (MONTH, YEAR, but this produces a different result:
@lcobucci commented on GitHub (Aug 19, 2019):
How about adding new columns to the query and aliasing them?
@core23 commented on GitHub (Aug 19, 2019):
You mean hidden columns? It's the same problem like using
addGroupBy('MONTH(i.invoiceDate)'), because it's a new field in the select section.@lcobucci commented on GitHub (Aug 20, 2019):
That sounds odd, could you send a PR with a functional test so that we can investigate that together?