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

Open
opened 2026-01-22 15:52:12 +01:00 by admin · 0 comments
Owner

Originally created by @va5ja on GitHub (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 https://github.com/doctrine/orm/pull/11825

Originally created by @va5ja on GitHub (Mar 5, 2025). ### Bug Report | Q | A |-------------------------------------------- | ------ | Version | 3.3.2 #### Summary A simple query builder or DQL statement like the following: ```PHP 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: ```PHP 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: ```PHP 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 https://github.com/doctrine/orm/pull/11825
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7483