phalcon/cphalcon · error · Phalcon\Mvc\Model\Exceptions\RelationAliasMustBeString
Relation alias must be a string in the HasMany relation of…
Error message
Relation alias must be a string in the HasMany relation of model '{entityName}' with Reference Model '{referencedEntity}' What it means
Thrown by addHasMany when the 'alias' option exists but is not a string. The manager needs a string alias to build its lowercased alias index for retrieving the relation later via getRelationByAlias or magic property access.
Solutions
- Provide the alias as a string: $this->hasMany(..., ['alias' => 'parts'])
- Drop the alias option to use the default naming
- Ensure the value is not a class constant that resolves to a non-string
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at phalcon/Mvc/Model/Manager.zep:433 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/98215fa4ff631394.
Report an issue: GitHub.
Appendix: source
Thrown at phalcon/Mvc/Model/Manager.zep:433
}
/**
* Create a relationship instance
*/
let relation = new Relation(
Relation::HAS_MANY,
referencedModel,
fields,
referencedFields,
options
);
/**
* Check an alias for the relation
*/
if fetch alias, options["alias"] {
if unlikely typeof alias != "string" {
throw new RelationAliasMustBeString("HasMany", entityName, referencedEntity);
}
let lowerAlias = strtolower(alias);
} else {
let lowerAlias = referencedEntity;
}
/**
* Append a new relationship
* Update the global alias
* Update the relations
*/
let relations[] = relation,
this->aliases[entityName . "$" . lowerAlias] = relation,
this->hasMany[keyRelation] = relations;
/**
* Get existing relations by modelView on GitHub (pinned to b7419de9cd)