phalcon/cphalcon · error · AmbiguousJoinRelation
There is more than one relation between models
Error message
There is more than one relation between models '{from}' and '{join}', the join must be done using an alias, when preparing: {phql} What it means
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.
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.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at phalcon/Mvc/Model/Query.zep:2843 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/b64b6b915f7b3a57.
Report an issue: GitHub.
Appendix: source
Thrown at phalcon/Mvc/Model/Query.zep:2843
fromModelName,
modelNameAlias
);
if relation === false {
/**
* Check for relations between models
*/
let relations = manager->getRelationsBetween(
fromModelName,
modelNameAlias
);
if typeof relations == "array" {
/**
* More than one relation must throw an exception
*/
if unlikely count(relations) != 1 {
throw new AmbiguousJoinRelation(fromModelName, joinModel, this->phql);
}
/**
* Get the first relationship
*/
let relation = relations[0];
}
}
/*
* Valid relations are objects
*/
if typeof relation == "object" {
/**
* Get the related model alias of the left part
*/
let modelAlias = sqlModelsAliases[fromModelName];
View on GitHub (pinned to b7419de9cd)