{"record":{"id":"769dd83711da891d","repo":"phalcon/cphalcon","slug":"when-having-is-set-there-should-be-columns-option","errorCode":null,"errorMessage":"When having is set there should be columns option provided for which calculate row count","messagePattern":"When having is set there should be columns option provided for which calculate row count","errorType":"exception","errorClass":"Phalcon\\Paginator\\Exceptions\\MissingColumnsForHaving","httpStatus":null,"severity":"error","filePath":"phalcon/Paginator/Adapter/QueryBuilder.zep","lineNumber":189,"sourceCode":"\n        /**\n         * Execute the query an return the requested slice of data\n         */\n        let items = query->execute();\n\n        let hasHaving = !empty totalBuilder->getHaving();\n\n        let groups = totalBuilder->getGroupBy();\n\n        let hasGroup = !empty groups;\n\n        /**\n         * Change the queried columns by a COUNT(*)\n         */\n\n        if hasHaving && !hasGroup {\n            if unlikely empty columns {\n                throw new MissingColumnsForHaving();\n            }\n\n            totalBuilder->columns(columns);\n        } else {\n            let hasDistinct    = false,\n                builderColumns = builder->getColumns();\n\n            if typeof builderColumns == \"string\" && stripos(trim(builderColumns), \"DISTINCT \") === 0 {\n                let distinctColumn = trim(substr(trim(builderColumns), 9));\n                let hasDistinct = true;\n\n                if strpos(distinctColumn, \",\") !== false {\n                    totalBuilder->columns([\"DISTINCT \" . distinctColumn]);\n                    let hasMultipleGroups = true;\n                } else {\n                    totalBuilder->columns(\n                        [\"COUNT(DISTINCT \" . distinctColumn . \") AS [rowcount]\"]\n                    );","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Paginator/Adapter/QueryBuilder.zep#L171-L207","documentation":"Error \"When having is set there should be columns option provided for which calculate row count\" thrown in phalcon/cphalcon.","triggerScenarios":"Thrown at phalcon/Paginator/Adapter/QueryBuilder.zep:189 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":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}