{"record":{"id":"59916ec7b53bbebb","repo":"phalcon/cphalcon","slug":"model-modelname-does-not-define-a-relation-wit","errorCode":null,"errorMessage":"Model '{modelName}' does not define a relation with alias '{alias}'","messagePattern":"Model '(.+?)' does not define a relation with alias '(.+?)'","errorType":"exception","errorClass":"Phalcon\\Mvc\\Model\\Exceptions\\UnknownEagerRelation","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model/Eager/Loader.zep","lineNumber":163,"sourceCode":"     *\n     * @param array $parents attribute-keyed row arrays at the root, or\n     *                       ModelInterface / Row instances below it\n     */\n    protected function buildMap(\n        array parents,\n        string modelName,\n        array tree\n    ) -> array {\n        var alias, node, relation;\n        array map;\n\n        let map = [];\n\n        for alias, node in tree {\n            let relation = this->manager->getRelationByAlias(modelName, alias);\n\n            if unlikely typeof relation !== \"object\" {\n                throw new UnknownEagerRelation(modelName, alias);\n            }\n\n            let map[strtolower(alias)] = this->buildNode(\n                relation,\n                alias,\n                parents,\n                node\n            );\n        }\n\n        return map;\n    }\n\n    /**\n     * Builds a single map node: one query, indexed by the referenced field.\n     */\n    protected function buildNode(\n        <RelationInterface> relation,","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model/Eager/Loader.zep#L145-L181","documentation":"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.","triggerScenarios":"Thrown at phalcon/Mvc/Model/Eager/Loader.zep:163 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the alias spelling against the 'alias' option set on the relation in the model's initialize()","Define the missing relation on the parent model (belongsTo/hasMany/etc.) with that alias","Remember aliases are stored lowercased; use the exact alias string you declared"],"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"}