{"record":{"id":"b64b6b915f7b3a57","repo":"phalcon/cphalcon","slug":"there-is-more-than-one-relation-between-models-f","errorCode":null,"errorMessage":"There is more than one relation between models '{from}' and '{join}', the join must be done using an alias, when preparing: {phql}","messagePattern":"There is more than one relation between models '(.+?)' and '(.+?)', the join must be done using an alias, when preparing: (.+?)","errorType":"exception","errorClass":"AmbiguousJoinRelation","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model/Query.zep","lineNumber":2843,"sourceCode":"                        fromModelName,\n                        modelNameAlias\n                    );\n\n                    if relation === false {\n                        /**\n                         * Check for relations between models\n                         */\n                        let relations = manager->getRelationsBetween(\n                            fromModelName,\n                            modelNameAlias\n                        );\n\n                        if typeof relations == \"array\" {\n                            /**\n                             * More than one relation must throw an exception\n                             */\n                            if unlikely count(relations) != 1 {\n                                throw new AmbiguousJoinRelation(fromModelName, joinModel, this->phql);\n                            }\n\n                            /**\n                             * Get the first relationship\n                             */\n                            let relation = relations[0];\n                        }\n                    }\n\n                    /*\n                     * Valid relations are objects\n                     */\n                    if typeof relation == \"object\" {\n                        /**\n                         * Get the related model alias of the left part\n                         */\n                        let modelAlias = sqlModelsAliases[fromModelName];\n","sourceCodeStart":2825,"sourceCodeEnd":2861,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model/Query.zep#L2825-L2861","documentation":"Thrown in Query::getJoins when no explicit relation was found between the FROM model and the joined model, and getRelationsBetween returns more than one relation, making the join path ambiguous. The PHQL must disambiguate via an alias matching a named relation.","triggerScenarios":"Thrown at phalcon/Mvc/Model/Query.zep:2843 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add an alias to the join matching the relation alias: JOIN App\\Models\\Payments AS PaidVia.","Define unique hasMany/hasManyToMany relation aliases on the models.","Inspect getRelationsBetween on the two models and reduce to a single relation if the join should be implicit."],"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"}