{"record":{"id":"202911031b5f1721","repo":"phalcon/cphalcon","slug":"relation-alias-must-be-a-string-in-the-hasone-rela","errorCode":null,"errorMessage":"Relation alias must be a string in the HasOne relation of model '{entityName}' with Reference Model '{referencedEntity}'","messagePattern":"Relation alias must be a string in the HasOne 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":653,"sourceCode":"        }\n\n        /**\n         * Create a relationship instance\n         */\n        let relation = new Relation(\n            Relation::HAS_ONE,\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(\"HasOne\", 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->hasOne[keyRelation] = relations;\n\n        /**\n         * Get existing relations by model","sourceCodeStart":635,"sourceCodeEnd":671,"githubUrl":"https://github.com/phalcon/cphalcon/blob/b7419de9cd0a8a3f48441ead84c9f8415d463e25/phalcon/Mvc/Model/Manager.zep#L635-L671","documentation":"Thrown by Model Manager when registering a HasOne relation whose options['alias'] is not a string. Relation aliases are lowercased string keys used by getRelated, so other types are rejected. Pass a string alias in the relation options.","triggerScenarios":"Thrown at phalcon/Mvc/Model/Manager.zep:653 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a string alias: $this->hasOne(..., ['alias' => 'profile'])","Omit the alias option to fall back to the default","Check for accidentally passing an array or a non-string constant as alias"],"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"}