phalcon/cphalcon · error · ModelRequired

At least one model is required to build the query

Error message

At least one model is required to build the query

What it means

Thrown in Builder::getPhql: no models have been set on the builder (from()/addFrom never called or empty), so there is no table to build the PHQL FROM clause from. The input at fault is the builder's model list.

Solutions

  1. Call from('App\Models\X') or addFrom() before getPhql()/getQuery().
  2. When using from(['A','B']), ensure the array is non-empty.
  3. Validate builder configuration in factories before building.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at phalcon/Mvc/Model/Query/Builder.zep:714 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/f1f1db7144c99ccf. Report an issue: GitHub.

Appendix: source

Thrown at phalcon/Mvc/Model/Query/Builder.zep:714

        var container, models, conditions, model, metaData, modelInstance,
            primaryKeys, firstPrimaryKey, columnMap, modelAlias,
            attributeField, phql, column, columns, selectedColumns,
            selectedColumn, selectedModel, selectedModels, columnAlias,
            modelColumnAlias, joins, join, joinModel, joinConditions,
            joinAlias, joinType, group, groupItems, groupItem, having, order,
            orderItems, orderItem, limit, number, offset, forUpdate, distinct;
        bool noPrimary;

        let container = this->container;
        if typeof container != "object" {
            let container = Di::getDefault(),
                this->container = container;
        }

        let models = this->models;
        if typeof models == "array" {
            if unlikely empty models {
                throw new ModelRequired();
            }
        } else {
            if unlikely !models {
                throw new ModelRequired();
            }
        }

        let conditions = this->conditions;

        if is_numeric(conditions) {
            /**
             * If the conditions is a single numeric field. We internally create
             * a condition using the related primary key
             */
            if typeof models == "array" {
                if unlikely count(models) > 1 {
                    throw new BuilderConditionInvalid();
                }

View on GitHub (pinned to b7419de9cd)