{"record":{"id":"98215fa4ff631394","repo":"phalcon/cphalcon","slug":"relation-alias-must-be-a-string-in-the-hasmany-rel","errorCode":null,"errorMessage":"Relation alias must be a string in the HasMany relation of model '{entityName}' with Reference Model '{referencedEntity}'","messagePattern":"Relation alias must be a string in the HasMany relation of model '(.+?)' with Reference Model '(.+?)'","errorType":"exception","errorClass":"Phalcon\\Mvc\\Model\\Exceptions\\RelationAliasMustBeString","httpStatus":null,"severity":"error","filePath":"phalcon/Mvc/Model/Manager.zep","lineNumber":433,"sourceCode":"        }\n\n        /**\n         * Create a relationship instance\n         */\n        let relation = new Relation(\n            Relation::HAS_MANY,\n            referencedModel,\n            fields,\n            referencedFields,\n            options\n        );\n\n        /**\n         * Check an alias for the relation\n         */\n        if fetch alias, options[\"alias\"] {\n            if unlikely typeof alias != \"string\" {\n                throw new RelationAliasMustBeString(\"HasMany\", entityName, referencedEntity);\n            }\n\n            let lowerAlias = strtolower(alias);\n        } else {\n            let lowerAlias = referencedEntity;\n        }\n\n        /**\n         * Append a new relationship\n         * Update the global alias\n         * Update the relations\n         */\n        let relations[] = relation,\n            this->aliases[entityName . \"$\" . lowerAlias] = relation,\n            this->hasMany[keyRelation] = relations;\n\n        /**\n         * Get existing relations by model","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model/Manager.zep#L415-L451","documentation":"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.","triggerScenarios":"Thrown at phalcon/Mvc/Model/Manager.zep:433 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"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"}