{"record":{"id":"f18dc2af84ddcad6","repo":"doctrine/orm","slug":"cannot-count-query-which-selects-two-from-componen-f18dc2","errorCode":null,"errorMessage":"Cannot count query which selects two FROM components, cannot make distinction","messagePattern":"Cannot count query which selects two FROM components, cannot make distinction","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Tools/Pagination/LimitSubqueryOutputWalker.php","lineNumber":517,"sourceCode":"        foreach ($AST->selectClause->selectExpressions as $idx => $expr) {\n            $expr->hiddenAliasResultVariable = $hiddens[$idx];\n        }\n\n        return $innerSql;\n    }\n\n    /** @return string[] */\n    private function getSQLIdentifier(SelectStatement $AST): array\n    {\n        // Find out the SQL alias of the identifier column of the root entity.\n        // It may be possible to make this work with multiple root entities but that\n        // would probably require issuing multiple queries or doing a UNION SELECT.\n        // So for now, it's not supported.\n\n        // Get the root entity and alias from the AST fromClause.\n        $from = $AST->fromClause->identificationVariableDeclarations;\n        if (count($from) !== 1) {\n            throw new RuntimeException('Cannot count query which selects two FROM components, cannot make distinction');\n        }\n\n        $fromRoot       = reset($from);\n        $rootAlias      = $fromRoot->rangeVariableDeclaration->aliasIdentificationVariable;\n        $rootClass      = $this->getMetadataForDqlAlias($rootAlias);\n        $rootIdentifier = $rootClass->identifier;\n\n        // For every identifier, find out the SQL alias by combing through the ResultSetMapping\n        $sqlIdentifier = [];\n        foreach ($rootIdentifier as $property) {\n            if (isset($rootClass->fieldMappings[$property])) {\n                foreach (array_keys($this->rsm->fieldMappings, $property, true) as $alias) {\n                    if ($this->rsm->columnOwnerMap[$alias] === $rootAlias) {\n                        $sqlIdentifier[$property] = $alias;\n                    }\n                }\n            }\n","sourceCodeStart":499,"sourceCodeEnd":535,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/Tools/Pagination/LimitSubqueryOutputWalker.php#L499-L535","documentation":"Error \"Cannot count query which selects two FROM components, cannot make distinction\" thrown in doctrine/orm.","triggerScenarios":"Thrown at src/Tools/Pagination/LimitSubqueryOutputWalker.php:517 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d9b9ff73016bf598ae07515f97289ce8074e97a5","analyzedAt":"2026-08-21T06:13:15.863Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}