{"record":{"id":"e0f62ec84e09bdc6","repo":"phalcon/cphalcon","slug":"cannot-use-alias-as-join-alias-because-it-was","errorCode":null,"errorMessage":"Cannot use '{alias}' as join alias because it was already used, when preparing: {phql}","messagePattern":"Cannot use '(.+?)' as join alias because it was already used, when preparing: (.+?)","errorType":"exception","errorClass":"JoinAliasAlreadyUsed","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model/Query.zep","lineNumber":2641,"sourceCode":"                realModelName = joinData[\"modelName\"],\n                completeSource = [source, schema];\n\n            /**\n             * Check join alias\n             */\n            let joinType = this->getJoinType(joinItem);\n\n            /**\n             * Process join alias\n             */\n            if fetch aliasExpr, joinItem[\"alias\"] {\n                let alias = aliasExpr[\"name\"];\n\n                /**\n                 * Check if alias is unique\n                 */\n                if unlikely isset joinModels[alias] {\n                    throw new JoinAliasAlreadyUsed(alias, this->phql);\n                }\n\n                /**\n                 * Add the alias to the source\n                 */\n                let completeSource[] = alias;\n\n                /**\n                 * Set the join type\n                 */\n                let joinTypes[alias] = joinType;\n\n                /**\n                 * Update alias: alias\n                 */\n                let sqlAliases[alias] = alias;\n\n                /**","sourceCodeStart":2623,"sourceCodeEnd":2659,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model/Query.zep#L2623-L2659","documentation":"Thrown in Query::getJoins while processing join aliases: an alias given to a JOIN is already registered in joinModels (used by the FROM clause or an earlier join), so the same alias would map to two models. The input at fault is the duplicate alias name in the PHQL.","triggerScenarios":"Thrown at phalcon/Mvc/Model/Query.zep:2641 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Give the join a unique alias, e.g. JOIN App\\Models\\Roles AS r2 when r is taken.","Rename the conflicting alias in the SELECT or WHERE clauses accordingly.","Review generated PHQL for alias reuse when building queries programmatically."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b7419de9cd0a8a3f48441ead84c9f8415d463e25","analyzedAt":"2026-08-21T06:21:18.811Z","contentChangedAt":"2026-08-21T06:21:18.811Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}