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

Failure when selecting a NEW DTO with only DTO arguments #11859

Open
va5ja opened this issue Mar 5, 2025 · 0 comments
Open

Failure when selecting a NEW DTO with only DTO arguments #11859

va5ja opened this issue Mar 5, 2025 · 0 comments

Comments

@va5ja
Copy link

va5ja commented Mar 5, 2025

Bug Report

Q A
Version 3.3.2

Summary

A simple query builder or DQL statement like the following:

return $this->createQueryBuilder('t')
    ->select(
        'NEW App\Dto\MainDto(
            NEW App\Dto\NestedDto(t.field),
            NEW App\Dto\NestedDto(t.field)
        )'
    )
    ->getQuery()
    ->getResult();

fails with error:

Warning: Undefined array key "class"

If we change the first argument to let's say a string, so:

return $this->createQueryBuilder('t')
    ->select(
        'NEW App\Dto\MainDto(
            t.field,
            NEW App\Dto\NestedDto(t.field),
            NEW App\Dto\NestedDto(t.field)
        )'
    )
    ->getQuery()
    ->getResult();

then the query works.

Current behavior

Having a select with a single NEW DTO with only DTO arguments fails.

Expected behavior

The query works fine.

How to reproduce

It has something to do with ObjectHydrator::hydrateRowData() and more specifically AbstractHydrator::gatherRowData() at the following part:

        foreach ($this->resultSetMapping()->nestedNewObjectArguments as $objIndex => ['ownerIndex' => $ownerIndex, 'argIndex' => $argIndex]) {
            if (! isset($rowData['newObjects'][$ownerIndex . ':' . $argIndex])) {
                continue;
            }

            $newObject = $rowData['newObjects'][$ownerIndex . ':' . $argIndex];
            unset($rowData['newObjects'][$ownerIndex . ':' . $argIndex]);

            $obj = $newObject['class']->newInstanceArgs($newObject['args']);

            $rowData['newObjects'][$ownerIndex]['args'][$argIndex] = $obj;
        }

        foreach ($rowData['newObjects'] as $objIndex => $newObject) {
            $obj = $newObject['class']->newInstanceArgs($newObject['args']);

            $rowData['newObjects'][$objIndex]['obj'] = $obj;
        }

The last $newObject['class'] doesn't exist.

It could be that this is fixed in #11825

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

No branches or pull requests

1 participant