{"record":{"id":"e03bdb9cd8ea61fb","repo":"doctrine/orm","slug":"no-metadata-for-dql-alias-s-e03bdb","errorCode":null,"errorMessage":"No metadata for DQL alias: %s","messagePattern":"No metadata for DQL alias: (.+?)","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"src/Query/TreeWalkerAdapter.php","lineNumber":88,"sourceCode":"     * Retrieves the Query Instance responsible for the current walkers execution.\n     */\n    protected function _getQuery(): AbstractQuery\n    {\n        return $this->query;\n    }\n\n    /**\n     * Retrieves the ParserResult.\n     */\n    protected function _getParserResult(): ParserResult\n    {\n        return $this->parserResult;\n    }\n\n    protected function getMetadataForDqlAlias(string $dqlAlias): ClassMetadata\n    {\n        return $this->queryComponents[$dqlAlias]['metadata']\n            ?? throw new LogicException(sprintf('No metadata for DQL alias: %s', $dqlAlias));\n    }\n}\n","sourceCodeStart":70,"sourceCodeEnd":91,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/Query/TreeWalkerAdapter.php#L70-L91","documentation":"TreeWalkerAdapter is Doctrine ORM's convenience base class for custom DQL tree walkers that visit the parsed AST while a query executes. getMetadataForDqlAlias() returns the ClassMetadata the parser stored in queryComponents for a DQL alias. This LogicException fires when a walker asks for an alias the parser never registered, meaning that alias is not a query component of the SELECT statement being walked.","triggerScenarios":"A TreeWalkerAdapter subclass calls getMetadataForDqlAlias($alias) with an alias absent from $this->getQueryComponents(): an alias that only exists inside a subquery scope, a typo'd or case-mismatched alias, or an alias scraped from an AST node (e.g. a Join or SelectExpression) that is not a top-level component. It also fires when walker code mixes components from one query with the AST of another.","commonSituations":"Custom walkers for soft-delete or multi-tenant filters, Gedmo-style behavioral walkers reused on new query shapes, walker code copied between projects, and ORM major-version upgrades where the parser's AST or component keys changed.","solutions":["Resolve aliases only from getQueryComponents() (e.g. iterate that array) instead of re-deriving them from AST nodes.","Guard each lookup: if (! isset($this->getQueryComponents()[$dqlAlias]['metadata'])) skip or handle that node.","Debug once by dumping array_keys($this->getQueryComponents()) next to the alias you pass.","After upgrading Doctrine ORM majors, re-run tests that execute queries with your walker hint attached."],"exampleFix":"// before - inside a custom TreeWalkerAdapter subclass\n$metadata = $this->getMetadataForDqlAlias($alias); // LogicException when $alias came from a subquery\n\n// after\n$components = $this->getQueryComponents();\nif (isset($components[$alias]['metadata'])) {\n    $metadata = $this->getMetadataForDqlAlias($alias);\n} else {\n    return; // alias is not a component of this query: skip it\n}","handlingStrategy":"validation","validationCode":"// inside your TreeWalkerAdapter subclass, before resolving metadata\n$components = $this->getQueryComponents();\nif (! isset($components[$dqlAlias]['metadata'])) {\n    return; // alias is not a component of the walked query: skip or log it\n}\n$metadata = $this->getMetadataForDqlAlias($dqlAlias);","typeGuard":null,"tryCatchPattern":"LogicException signals a walker bug, not a runtime condition: catch \\LogicException only to log the walker class, the DQL and the offending alias, then rethrow so the defect surfaces.","preventionTips":["Derive aliases from getQueryComponents(), never hardcode them or scrape them from unrelated AST nodes.","Execute queries with the walker hint in tests; inspecting the AST alone will not surface this.","Treat LogicException from a walker as fail-fast: never ship a catch that swallows it."],"tags":["doctrine-orm","dql","tree-walker","ast","class-metadata"],"backgroundTag":"unknown-query-alias","analyzedSha":"d9b9ff73016bf598ae07515f97289ce8074e97a5","analyzedAt":"2026-08-21T06:13:15.863Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}