{"record":{"id":"44322e2d53827124","repo":"doctrine/orm","slug":"cannot-count-query-that-uses-a-having-clause-use","errorCode":null,"errorMessage":"Cannot count query that uses a HAVING clause. Use the output walkers for pagination","messagePattern":"Cannot count query that uses a HAVING clause\\. Use the output walkers for pagination","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Tools/Pagination/CountWalker.php","lineNumber":30,"sourceCode":"use RuntimeException;\n\nuse function count;\nuse function reset;\n\n/**\n * Replaces the selectClause of the AST with a COUNT statement.\n */\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","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/doctrine/orm/blob/d9b9ff73016bf598ae07515f97289ce8074e97a5/src/Tools/Pagination/CountWalker.php#L12-L48","documentation":"Error \"Cannot count query that uses a HAVING clause. Use the output walkers for pagination\" thrown in doctrine/orm.","triggerScenarios":"Thrown at src/Tools/Pagination/CountWalker.php:30 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"}