{"record":{"id":"b964c8b34a9f4160","repo":"doctrine/orm","slug":"cannot-count-query-which-selects-two-from-componen-b964c8","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/CountWalker.php","lineNumber":37,"sourceCode":" */\nclass CountWalker extends TreeWalkerAdapter\n{\n    /**\n     * Distinct mode hint name.\n     */\n    public const HINT_DISTINCT = 'doctrine_paginator.distinct';\n\n    public function walkSelectStatement(SelectStatement $selectStatement): void\n    {\n        if ($selectStatement->havingClause) {\n            throw new RuntimeException('Cannot count query that uses a HAVING clause. Use the output walkers for pagination');\n        }\n\n        // Get the root entity and alias from the AST fromClause\n        $from = $selectStatement->fromClause->identificationVariableDeclarations;\n\n        if (count($from) > 1) {\n            throw new RuntimeException('Cannot count query which selects two FROM components, cannot make distinction');\n        }\n\n        $distinct = $this->_getQuery()->getHint(self::HINT_DISTINCT);\n\n        $countPathExpressionOrLiteral = '*';\n        if ($distinct) {\n            $fromRoot            = reset($from);\n            $rootAlias           = $fromRoot->rangeVariableDeclaration->aliasIdentificationVariable;\n            $rootClass           = $this->getMetadataForDqlAlias($rootAlias);\n            $identifierFieldName = $rootClass->getSingleIdentifierFieldName();\n\n            $pathType = PathExpression::TYPE_STATE_FIELD;\n            if (isset($rootClass->associationMappings[$identifierFieldName])) {\n                $pathType = PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION;\n            }\n\n            $countPathExpressionOrLiteral       = new PathExpression(\n                PathExpression::TYPE_STATE_FIELD | PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION,","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/Tools/Pagination/CountWalker.php#L19-L55","documentation":"Error \"Cannot count query which selects two FROM components, cannot make distinction\" thrown in doctrine/orm.","triggerScenarios":"Thrown at src/Tools/Pagination/CountWalker.php:37 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"}