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

Relation alias must be a string in the BelongsTo relation of

Error message

Relation alias must be a string in the BelongsTo relation of model '{entityName}' with Reference Model '{referencedEntity}'

What it means

Error "Relation alias must be a string in the BelongsTo relation of model '{entityName}' with Reference Model '{referencedEntity}'" thrown in phalcon/cphalcon.

Source

Thrown at phalcon/Mvc/Model/Manager.zep:339

        }

        /**
         * Create a relationship instance
         */
        let relation = new Relation(
            Relation::BELONGS_TO,
            referencedModel,
            fields,
            referencedFields,
            options
        );

        /**
         * Check an alias for the relation
         */
        if fetch alias, options["alias"] {
            if unlikely typeof alias != "string" {
                throw new RelationAliasMustBeString("BelongsTo", entityName, referencedEntity);
            }

            let lowerAlias = strtolower(alias);
        } else {
            let lowerAlias = referencedEntity;
        }

        /**
         * Append a new relationship
         * Update the global alias
         * Update the relations
         */
        let relations[] = relation,
            this->aliases[entityName . "$" . lowerAlias] = relation,
            this->belongsTo[keyRelation] = relations;

        /**
         * Get existing relations by model

View on GitHub (pinned to b7419de9cd)

When it happens

Trigger: Thrown at phalcon/Mvc/Model/Manager.zep:339 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/45ddf2b672c2fb78. Report an issue: GitHub.