phalcon/cphalcon · error · NoModelForAlias

There is no model related to model or alias

Error message

There is no model related to model or alias '{model}', when executing: {phql}

What it means

Thrown in Query::getQualified when the column's domain is a known alias but no corresponding model instance exists in this->sqlAliasesModelsInstances, so column renaming/mapping cannot be performed. This happens for aliases registered without a resolvable model.

Solutions

  1. Ensure the alias in FROM/JOIN references a real, loadable model class.
  2. Re-prepare the query so sqlAliasesModelsInstances is rebuilt after changing models.
  3. Check that the model namespace is correct and the class can be loaded by the models manager.
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

            if unlikely !fetch source, sqlAliases[columnDomain] {
                throw new UnknownModelOrAlias(columnDomain, "11", this->phql);
            }

            /**
             * Change the selected column by its real name on its mapped table
             */
            if Settings::get("orm.column_renaming") {
                /**
                 * Retrieve the corresponding model by its alias
                 */
                let sqlAliasesModelsInstances = this->sqlAliasesModelsInstances;

                /**
                 * We need the model instance to retrieve the reversed column
                 * map
                 */
                if unlikely !fetch model, sqlAliasesModelsInstances[columnDomain] {
                    throw new NoModelForAlias(columnDomain, this->phql);
                }

                let columnMap = metaData->getReverseColumnMap(model);
            } else {
                let columnMap = null;
            }

            if typeof columnMap == "array" {
                if unlikely !fetch realColumnName, columnMap[columnName] {
                    throw new ColumnNotInDomain(columnName, columnDomain, this->phql);
                }
            } else {
                let realColumnName = columnName;
            }
        } else {
            /**
             * If the column IR does not have a domain, we must check for
             * ambiguities

View on GitHub (pinned to b7419de9cd)