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

Add support for using nested DTOs #11576

Merged
merged 1 commit into from
Aug 19, 2024
Merged

Conversation

eltharin
Copy link
Contributor

For #11540 in good branch

This feature allow use of nested new operators

Co-authored-by: Tomas Norkūnas <[email protected]>
Co-authored-by: Sergey Protko <[email protected]>
Co-authored-by: Łukasz Zakrzewski <[email protected]>

Update docs/en/reference/dql-doctrine-query-language.rst

Co-authored-by: Claudio Zizza <[email protected]>
@greg0ire greg0ire added this to the 3.3.0 milestone Aug 19, 2024
@greg0ire greg0ire merged commit 6f93ceb into doctrine:3.3.x Aug 19, 2024
65 checks passed
@greg0ire
Copy link
Member

Thanks @eltharin !

@derrabus derrabus changed the title Re: Re: Add support for using nested DTOs Add support for using nested DTOs Aug 29, 2024
$query = $em->createQuery('SELECT NEW CustomerDTO(c.name, e.email, NEW AddressDTO(a.street, a.city, a.zip)) FROM Customer c JOIN c.email e JOIN c.address a');
$users = $query->getResult(); // array of CustomerDTO

Note that you can only pass scalar expressions or other Data Transfer Objects to the constructor.
Copy link
Member

Choose a reason for hiding this comment

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

@eltharin sorry, I forgot this during my review, but below there is a paragraph called EBNF with a grammar that you should probably update with your changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK => #11619

greg0ire added a commit to greg0ire/data-fixtures that referenced this pull request Oct 2, 2024
Now that we use phpDocumentor/guides and
doctrine/orm#11576 is merged, we can try
using captions instead of custom directives.
@setineos
Copy link

setineos commented Oct 4, 2024

With add support for using nested DTOs, how to use it with sprintf?

Currently I have this:

$result = $this->entityManager->createQueryBuilder('c')
    ->select(sprintf(
        'NEW %s(c.name, e.email)',
        CustomerDTO::class
    ))
    ->join('c.email', 'e')
    ->getQuery()
    ->getResult();

I would like to add NEW AddressDTO(a.street, a.city, a.zip) but with sprintf syntax.

@stetodd
Copy link

stetodd commented Oct 4, 2024

Have you tried:

    sprintf(
        'NEW %s(c.name, e.email, NEW %s(a.street, a.city, a.zip))',
        CustomerDTO::class,
        AddressDTO::class
    )

@setineos
Copy link

setineos commented Oct 4, 2024

It works perfectly!

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.

5 participants