phalcon/cphalcon · error · AmbiguousColumn

The column ' ' is ambiguous, when preparing

Error message

The column '{name}' is ambiguous, when preparing: {phql}

What it means

Thrown in Query::getQualified for a column without a domain: the column name matches attributes on more than one of the selected models (number > 1), so the generated SQL would be ambiguous. The input at fault is the unqualified column name in the PHQL.

Solutions

  1. Qualify the column with a model alias, e.g. u.id instead of id.
  2. Rename one of the conflicting model attributes if applicable.
  3. Alias the models in FROM/JOIN and prefix all shared-named columns.
Defensive patterns

Strategy: validation

When it happens

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

Appendix: source

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

                let realColumnName = columnName;
            }
        } else {
            /**
             * If the column IR does not have a domain, we must check for
             * ambiguities
             */
            let number = 0,
                hasModel = false;

            for model in this->modelsInstances {
                /**
                 * 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;

View on GitHub (pinned to b7419de9cd)