NEW Operator for DTO construction supporting entities aswell as scalar expressions #9407
Unanswered
AndreRudolph
asked this question in
Support Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Let's assume I have a scenario where I have a collection and a link entity. A Collection can have multiple links assigned to.
Collection class (minimized example):
and Link class (minimized example):
Let's say I want to retrieve a list of collections with a count of assigned links for each collection. Since I don't want to have an array and instead just one object per row I checked the doctrines documentation and it is possible to create objects from classes that don't need to be an entity itself:
According to https://www.doctrine-project.org/projects/doctrine-orm/en/2.9/reference/dql-doctrine-query-language.html#new-operator-syntax it is only possible to pass scalar expressions to a NEW constructor in DQL. I am wondering what the reason was to only allow scalar expressions and not an entity itself?
If I want to have all the informations of the collection entity (name, description, etc.) would have to create possibly a very large and unmaintainable constructor and query string by listing every single column (property) field of c. Wouldn't it be nice to just pass "c" as the collection entity directly into the CollectionLinkCountViewModel constructor? Like this:
Beta Was this translation helpful? Give feedback.
All reactions