Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NewObjectExpression: Allows use of nested new operators #6709

Closed

Conversation

fesor
Copy link

@fesor fesor commented Sep 19, 2017

Covers #4687, #6573

This PR adds ability to use aggregation of DTOs as query result:

$dql = '
    SELECT
        new UserDTO(
           u.id,
           u.name,
           new AddressDTO(
                address.country,
                address.city,
                address.street,
                address.postcode
           )
        )
    FROM User u
    JOIN u.location address
';

Use cases:

  • reporting and aggregations results
  • read-only queries

@fesor fesor changed the title Allows use of nested new operators NewObjectExpression: Allows use of nested new operators Sep 19, 2017
foreach ($rowData['newObjects'] as $objIndex => $newObject) {
$class = $newObject['class'];
$args = $newObject['args'];
ksort($args);
Copy link
Author

@fesor fesor Sep 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs test case (probably when new object is given as not last argument)

@@ -324,6 +325,30 @@ protected function gatherRowData(array $data, array &$id, array &$nonemptyCompon
}
}

foreach ($this->_rsm->nestedNewObjectArguments as $objIndex => ['ownerIndex' => $ownerIndex, 'argIndex' => $argIndex]) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like scrutinizer doesn't know how to deal with destructuring.

@lcobucci
Copy link
Member

@fesor looks like this patch is going in a nice way, however I wonder that we should rather do this on v3 instead. Not sure about what @guilhermeblanco and @Ocramius think about this, but I believe it's about time to do a feature freeze on 2.x.

@Ocramius
Copy link
Member

Ocramius commented Oct 29, 2017 via email

@Majkl578 Majkl578 added this to the 3.0 milestone Dec 26, 2017
@Majkl578 Majkl578 added the DQL label Jan 1, 2018
@fesor fesor force-pushed the feature/nested-new-operator branch from 310b071 to 93bb1a5 Compare January 27, 2018 15:37
@fesor fesor force-pushed the feature/nested-new-operator branch from 93bb1a5 to f7c4643 Compare January 27, 2018 15:40
@fesor
Copy link
Author

fesor commented Jan 27, 2018

@Ocramius rebased on master.

@tkleinhakisa
Copy link
Contributor

Very nice! Does it handle collections ? eg if User has multiple addresses and constructor param is an array in UserDTO

@fesor
Copy link
Author

fesor commented Jan 27, 2018

@tkleinhakisa you mean handling *-to-many relations? Currently no... need to check how many changes in hydrator is required to make it possible.

I think that whole hydration system should be refactored so this and many other use cases could be possible without huge overhead, like the one in #2553 for example. But in order to make things both maintainable and performant, this would require some kind of inlining functionality and code generation...

@Majkl578
Copy link
Contributor

I'd probably suggest to postpone further work here for now if it requires further redesign. 2.x branch is in feature-freeze and for 3.0 we've been discussing a full DQL parser rewrite. No roadmap for that yet, but I've already been prepping a switch to Hoa\Compiler.

@joshhornby
Copy link

What are the chances of this making it into v3?

@Majkl578
Copy link
Contributor

It's definitely something I'd like to pursue since I believe DTOs have high potential, but likely not before rewriting the parser itself, for that see #7017.

Base automatically changed from master to old-prototype-3.x February 23, 2021 08:18
@derrabus
Copy link
Member

I'm closing this PR because it hasn't seen progress for several years. Please open a new one if you want to pick up the work one day.

@derrabus derrabus closed this May 11, 2022
@derrabus derrabus removed this from the 3.0.0 milestone May 11, 2022
@norkunas
Copy link
Contributor

norkunas commented Feb 7, 2024

Hoa packages are abandoned. Could this be reconsidered?

@greg0ire
Copy link
Member

greg0ire commented Feb 7, 2024

Please open a new one if you want to pick up the work one day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants