phalcon/cphalcon · error · Phalcon\Mvc\Model\Exceptions\RelationNotDefined
There is no defined relations for the model
Error message
There is no defined relations for the model '{className}' using alias '{alias}' What it means
Thrown by Model::getRelated when the manager has no relation registered under the given alias for the model (looked up lowercased). The alias must match one defined via hasMany/hasOne... with 'alias'. Check the relation alias spelling and definition.
Solutions
- Define the relation in the model's initialize() with a matching alias option
- Check the alias spelling/case used in the magic getter or getRelated() call
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at phalcon/Mvc/Model.zep:2311 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/b1e091a3011af787.
Report an issue: GitHub.
Appendix: source
Thrown at phalcon/Mvc/Model.zep:2311
*/
public function getRelated(string alias, arguments = null)
{
var relation, className, manager, result, lowerAlias;
/**
* Query the relation by alias
*/
let className = get_class(this),
manager = <ManagerInterface> this->modelsManager,
lowerAlias = strtolower(alias);
let relation = <RelationInterface> manager->getRelationByAlias(
className,
lowerAlias
);
if unlikely typeof relation !== "object" {
throw new RelationNotDefined(className, alias);
}
/**
* If there are any arguments, Manager with handle the caching of the records
*/
if arguments === null {
// /**
// * If the related records are already in cache and the relation is reusable,
// * we return the cached records.
// */
// if relation->isReusable() && this->isRelationshipLoaded(lowerAlias) {
// let result = this->related[lowerAlias];
// } else {
// /**
// * Call the 'getRelationRecords' in the models manager.
// */
// let result = manager->getRelationRecords(relation, this, arguments);
//View on GitHub (pinned to b7419de9cd)