{"record":{"id":"b82b175cf2829eca","repo":"doctrine/orm","slug":"cannot-count-query-which-selects-two-from-componen","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/CountOutputWalker.php","lineNumber":79,"sourceCode":"\n        $sql = parent::createSqlForFinalizer($selectStatement);\n\n        if ($selectStatement->groupByClause) {\n            return sprintf(\n                'SELECT COUNT(*) AS dctrn_count FROM (%s) dctrn_table',\n                $sql,\n            );\n        }\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 = $selectStatement->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":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/Tools/Pagination/CountOutputWalker.php#L61-L97","documentation":"Error \"Cannot count query which selects two FROM components, cannot make distinction\" thrown in doctrine/orm.","triggerScenarios":"Thrown at src/Tools/Pagination/CountOutputWalker.php:79 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"}