phalcon/cphalcon · error · UnknownModelOrAlias

Unknown model or alias

Error message

Unknown model or alias '{model}' ({tag}), when preparing: {phql}

What it means

Thrown in Query::getQualified when a column expression carries a domain (table/alias prefix) that is not present in this->sqlAliases, i.e. the PHQL references a model name or alias that was never declared in FROM/JOIN for this query. The tag parameter is an internal trace code.

Solutions

  1. Add the missing model to FROM/JOIN or fix the prefix spelling in the column reference.
  2. Use the declared alias instead of the full model name (or vice versa) in column references.
  3. When building PHQL programmatically, validate every domain against the registered aliases before execution.
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

            return [
                "type": "qualified",
                "name": columnName
            ];
        }

        let metaData = this->metaData;

        /**
         * Check if the qualified name has a domain
         */
        if fetch columnDomain, expr["domain"] {
            let sqlAliases = this->sqlAliases;

            /**
             * The column has a domain, we need to check if it's an alias
             */
            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);
                }

View on GitHub (pinned to b7419de9cd)