{"record":{"id":"39af9e85d025c8c9","repo":"phalcon/cphalcon","slug":"the-column-name-is-ambiguous-when-preparing","errorCode":null,"errorMessage":"The column '{name}' is ambiguous, when preparing: {phql}","messagePattern":"The column '(.+?)' is ambiguous, when preparing: (.+?)","errorType":"exception","errorClass":"AmbiguousColumn","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model/Query.zep","lineNumber":3255,"sourceCode":"                let realColumnName = columnName;\n            }\n        } else {\n            /**\n             * If the column IR does not have a domain, we must check for\n             * ambiguities\n             */\n            let number = 0,\n                hasModel = false;\n\n            for model in this->modelsInstances {\n                /**\n                 * Check if the attribute belongs to the current model\n                 */\n                if metaData->hasAttribute(model, columnName) {\n                    let number++;\n\n                    if unlikely number > 1 {\n                        throw new AmbiguousColumn(columnName, this->phql);\n                    }\n\n                    let hasModel = model;\n                }\n            }\n\n            /**\n             * After check in every model, the column does not belong to any of\n             * the selected models\n             */\n            if unlikely hasModel === false {\n                throw new ColumnNotInSelectedModels(columnName, \"1\", this->phql);\n            }\n\n            /**\n             * Check if the models property is correctly prepared\n             */\n            let models = this->models;","sourceCodeStart":3237,"sourceCodeEnd":3273,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model/Query.zep#L3237-L3273","documentation":"Error \"The column '{name}' is ambiguous, when preparing: {phql}\" thrown in phalcon/cphalcon.","triggerScenarios":"Thrown at phalcon/Mvc/Model/Query.zep:3255 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}