phalcon/cphalcon · error · Phalcon\Paginator\Exceptions\MissingColumnsForHaving
When having is set there should be columns option provided…
Error message
When having is set there should be columns option provided for which calculate row count
What it means
Thrown in Paginator\Adapter\QueryBuilder::getPaginate when a HAVING clause exists without GROUP BY: the count query needs an explicit 'columns' option listing which columns to count, otherwise the total cannot be computed against the having-filtered set. The input at fault is a builder with having() but no columns option passed to the paginator.
Solutions
- Pass the 'columns' option to the paginator when the builder uses having().
- Add a GROUP BY so the count can aggregate per group instead of requiring columns.
- Remove the having() clause if it is not needed for pagination totals.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at phalcon/Paginator/Adapter/QueryBuilder.zep:189 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/769dd83711da891d.
Report an issue: GitHub.
Appendix: source
Thrown at phalcon/Paginator/Adapter/QueryBuilder.zep:189
/**
* Execute the query an return the requested slice of data
*/
let items = query->execute();
let hasHaving = !empty totalBuilder->getHaving();
let groups = totalBuilder->getGroupBy();
let hasGroup = !empty groups;
/**
* Change the queried columns by a COUNT(*)
*/
if hasHaving && !hasGroup {
if unlikely empty columns {
throw new MissingColumnsForHaving();
}
totalBuilder->columns(columns);
} else {
let hasDistinct = false,
builderColumns = builder->getColumns();
if typeof builderColumns == "string" && stripos(trim(builderColumns), "DISTINCT ") === 0 {
let distinctColumn = trim(substr(trim(builderColumns), 9));
let hasDistinct = true;
if strpos(distinctColumn, ",") !== false {
totalBuilder->columns(["DISTINCT " . distinctColumn]);
let hasMultipleGroups = true;
} else {
totalBuilder->columns(
["COUNT(DISTINCT " . distinctColumn . ") AS [rowcount]"]
);View on GitHub (pinned to b7419de9cd)