{"record":{"id":"1993b404673d935b","repo":"doctrine/orm","slug":"argalias-does-not-exist","errorCode":null,"errorMessage":"{argAlias} does not exist","messagePattern":"(.+?) does not exist","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"src/Internal/Hydration/AbstractHydrator.php","lineNumber":372,"sourceCode":"            }\n        }\n\n        $nestedEntities = [];\n        /**@var string $argAlias */\n        foreach ($this->resultSetMapping()->nestedNewObjectArguments as ['ownerIndex' => $ownerIndex, 'argIndex' => $argIndex, 'argAlias' => $argAlias]) {\n            if (array_key_exists($argAlias, $rowData['newObjects'])) {\n                ksort($rowData['newObjects'][$argAlias]['args']);\n                $rowData['newObjects'][$ownerIndex]['args'][$argIndex] = $rowData['newObjects'][$argAlias]['class']->newInstanceArgs($rowData['newObjects'][$argAlias]['args']);\n                unset($rowData['newObjects'][$argAlias]);\n            } elseif (array_key_exists($argAlias, $rowData['data'])) {\n                if (! array_key_exists($argAlias, $nestedEntities)) {\n                    $nestedEntities[$argAlias]  = '';\n                    $rowData['data'][$argAlias] = $this->hydrateNestedEntity($rowData['data'][$argAlias], $argAlias);\n                }\n\n                $rowData['newObjects'][$ownerIndex]['args'][$argIndex] = $rowData['data'][$argAlias];\n            } else {\n                throw new LogicException($argAlias . ' does not exist');\n            }\n        }\n\n        foreach (array_keys($nestedEntities) as $entity) {\n            unset($rowData['data'][$entity]);\n        }\n\n        foreach ($rowData['newObjects'] as $objIndex => $newObject) {\n            ksort($rowData['newObjects'][$objIndex]['args']);\n            $obj = $rowData['newObjects'][$objIndex]['class']->newInstanceArgs($rowData['newObjects'][$objIndex]['args']);\n\n            $rowData['newObjects'][$objIndex]['obj'] = $obj;\n        }\n\n        return $rowData;\n    }\n\n    /** @param mixed[] $data pre-hydrated SQL Result Row. */","sourceCodeStart":354,"sourceCodeEnd":390,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/Internal/Hydration/AbstractHydrator.php#L354-L390","documentation":"LogicException from AbstractHydrator row processing (src/Internal/Hydration/AbstractHydrator.php:372) during hydration of `NEW` expressions in DQL (SELECT new DTO(...)). For nested new-object arguments, the hydrator looks up each argument's DQL alias either among collected new objects or row data; when an alias appears in neither, this 'X does not exist' is thrown — the SELECT list references an alias that produced no data in the row.","triggerScenarios":"DQL using NEW-object syntax where a nested argument alias is not (effectively) selected or mapped: e.g. SELECT new DTO(new Inner(u.id), a) ... where alias 'a' was joined but not selected, was pruned by the SQL walker, or the argument is a bare alias the parser recorded in nestedNewObjectArguments while the row contains no such key. Typical shapes: nested NEW expressions over joined entities, NEW combined with partial selects/HINT_FORCE_PARTIAL_LOAD, or scalar aliases reused across NEW arguments.","commonSituations":"DTO refactoring where someone moved an association into a nested new-expression but forgot to keep the alias in the SELECT; mixing NEW DTO(...) with joins whose aliases are only used inside the NEW argument; edge-case ORM versions where nested new-object arguments over joined aliases are incompletely supported — if the DQL looks legitimate, it may be an ORM bug worth reporting with a reproducer.","solutions":["Make sure every alias used as a NEW-expression argument is itself part of the SELECT list (SELECT new DTO(a.name), a FROM ... JOIN ...).","Flatten nested NEW expressions: select the inner new object alias explicitly, or build the nested object in PHP after hydrating the outer DTO.","Remove HINT_FORCE_PARTIAL_LOAD / partial-object hints on that query and retest — partial hydration can drop the data key the alias needs.","If the DQL is minimal and valid, reproduce on the latest patch release and report to doctrine/orm ( hydration LogicException 'alias does not exist')."],"exampleFix":"/* before: alias a is only used as a nested NEW argument, never selected */\nSELECT new UserDTO(new NameDTO(u.firstName, u.lastName), a)\nFROM App\\Entity\\User u JOIN u.address a\n\n/* after: select the joined alias so the row contains its data */\nSELECT new UserDTO(new NameDTO(u.firstName, u.lastName), a)\nFROM App\\Entity\\User u JOIN u.address a -- keep, but hydrate a explicitly if still missing:\n-- or: SELECT u, a FROM ... then map to DTO in PHP","handlingStrategy":"try-catch","validationCode":"// Before running, sanity-check that every alias used in NEW(...) args appears in the SELECT list\n$select = 'SELECT new DTO(new Inner(u.id), a) FROM App\\\\Entity\\\\User u JOIN u.address a';\n// ensure 'a' is selected/mapped; simplest static guard:\nforeach (['u', 'a'] as $alias) {\n    if (! preg_match('/\\b' . $alias . '\\b/', $select)) {\n        throw new LogicException(\"Alias {$alias} used in NEW() but absent from SELECT\");\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    $dtos = $query->getResult();\n} catch (\\LogicException $e) {\n    // 'X does not exist': NEW-expression alias produced no row data.\n    // Fall back to hydrating entities/scalars and constructing DTOs in PHP.\n    $rows = $em->createQuery('SELECT u, a FROM App\\\\Entity\\\\User u JOIN u.address a')->getResult();\n    $dtos = array_map(static fn ([$u, $a]) => new UserDTO(NameDTO::from($u), $a), $rows);\n}","preventionTips":["Keep NEW() argument aliases identical to aliases actually present in the SELECT clause.","Prefer flat NEW expressions or manual DTO mapping for structures with nested joined arguments.","Pin regression tests around DTO queries so ORM upgrades re-verify nested NEW hydration."],"tags":["doctrine-orm","dql","hydration","dto","new-expression"],"backgroundTag":"dql-new-expression-error","analyzedSha":"d9b9ff73016bf598ae07515f97289ce8074e97a5","analyzedAt":"2026-08-21T06:13:15.863Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}