phalcon/cphalcon · error · ColumnNotInSelectedModels

Column ' ' does not belong to any of the selected models (…

Error message

Column '{name}' does not belong to any of the selected models ({tag}), when preparing: {phql}

What it means

Thrown in Query::getQualified after scanning every model instance in the query: the column name matched no model attribute (hasModel === false), so the column cannot be resolved to any selected model's table. The tag is an internal trace code.

Solutions

  1. Fix the column name spelling against the model's attributes.
  2. Join or select the model that actually owns this column.
  3. With column renaming enabled, use the mapped property name rather than the database column name.
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

Thrown at phalcon/Mvc/Model/Query.zep:3267

                 * Check if the attribute belongs to the current model
                 */
                if metaData->hasAttribute(model, columnName) {
                    let number++;

                    if unlikely number > 1 {
                        throw new AmbiguousColumn(columnName, this->phql);
                    }

                    let hasModel = model;
                }
            }

            /**
             * After check in every model, the column does not belong to any of
             * the selected models
             */
            if unlikely hasModel === false {
                throw new ColumnNotInSelectedModels(columnName, "1", this->phql);
            }

            /**
             * Check if the models property is correctly prepared
             */
            let models = this->models;

            if unlikely typeof models != "array" {
                throw new ModelsListNotLoaded();
            }

            /**
             * Obtain the model's source from the models list
             */
            let className = get_class(hasModel);

            if unlikely !fetch source, models[className] {
                throw new ModelSourceNotFound(className, this->phql);

View on GitHub (pinned to b7419de9cd)