phalcon/cphalcon · error · Phalcon\Mvc\Model\Exceptions\UnknownEagerRelation

Model ' ' does not define a relation with alias

Error message

Model '{modelName}' does not define a relation with alias '{alias}'

What it means

Thrown during eager-load map building when the models manager's getRelationByAlias() for the parent model and the given alias does not return a relation object — the alias used in the eager path does not match any relation defined (or aliased) on the model.

Solutions

  1. Check the alias spelling against the 'alias' option set on the relation in the model's initialize()
  2. Define the missing relation on the parent model (belongsTo/hasMany/etc.) with that alias
  3. Remember aliases are stored lowercased; use the exact alias string you declared
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at phalcon/Mvc/Model/Eager/Loader.zep:163 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/59916ec7b53bbebb. Report an issue: GitHub.

Appendix: source

Thrown at phalcon/Mvc/Model/Eager/Loader.zep:163

     *
     * @param array $parents attribute-keyed row arrays at the root, or
     *                       ModelInterface / Row instances below it
     */
    protected function buildMap(
        array parents,
        string modelName,
        array tree
    ) -> array {
        var alias, node, relation;
        array map;

        let map = [];

        for alias, node in tree {
            let relation = this->manager->getRelationByAlias(modelName, alias);

            if unlikely typeof relation !== "object" {
                throw new UnknownEagerRelation(modelName, alias);
            }

            let map[strtolower(alias)] = this->buildNode(
                relation,
                alias,
                parents,
                node
            );
        }

        return map;
    }

    /**
     * Builds a single map node: one query, indexed by the referenced field.
     */
    protected function buildNode(
        <RelationInterface> relation,

View on GitHub (pinned to b7419de9cd)