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

Relation alias must be a string in the HasManytoMany…

Error message

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

What it means

Thrown by addHasManyToMany when the relation's 'alias' option is not a string. Like other relation types, the alias is lowercased and used as the index key for later alias-based lookups, so a non-string value is unusable.

Solutions

  1. Pass the alias as a string in the options array, e.g. ['alias' => 'categories']
  2. Remove the alias option if the default alias is acceptable
  3. Verify the option array structure — a misplaced element may put a non-string under 'alias'
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at phalcon/Mvc/Model/Manager.zep:554 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/92ea909db29ce10e. Report an issue: GitHub.

Appendix: source

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

            referencedFields,
            options
        );

        /**
         * Set extended intermediate relation data
         */
        relation->setIntermediateRelation(
            intermediateFields,
            intermediateModel,
            intermediateReferencedFields
        );

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

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

        /**
         * Append a new relationship
         */
        let relations[] = relation;

        /**
         * Update the global alias
         */
        let this->aliases[entityName . "$" . lowerAlias] = relation;

        /**

View on GitHub (pinned to b7419de9cd)