Help us shape the future of Go! Take the 2026 Go Developer Survey

morphmap

package
v1.20.0-alpha.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package morphmap holds the process-wide registry of polymorphic aliases shared by the orm and gorm packages. It mirrors fedaco's static Relation._morphMap (libs/fedaco/src/fedaco/ relations/relation.ts:31) while remaining safe for concurrent reads from many query goroutines.

Most app code interacts with the registry via the wrappers in package orm (orm.MorphMap, orm.MorphedModel, orm.MorphAlias). The lower-level gorm wrapper imports this package directly to resolve morph values during query construction without introducing a circular dependency on package orm.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AliasOf

func AliasOf(model any) (string, bool)

AliasOf returns the alias registered for the given model's underlying type.

func All

func All() map[string]reflect.Type

All returns a snapshot copy of the alias-to-type registry.

func Find

func Find(alias string) any

Find returns a fresh pointer to a new instance of the model registered under alias, or nil if no model is registered.

func MorphValue

func MorphValue(model any) (string, bool)

MorphValue resolves the morph alias for a model. Resolution order:

  1. model.MorphClass() if the model (or its pointer) implements ModelWithMorphClass
  2. global morph map (registered via Register)

Returns "" and false if neither resolves. The caller is then expected to fall back to GORM's `polymorphicValue:` tag or the parent's table name.

func Register

func Register(entries map[string]any, merge ...bool)

Register stores a set of alias-to-sample-model bindings. Subsequent calls merge with previously registered entries; later writes win on conflict. Pass false in the optional merge argument to replace the registry instead of merging.

func Reset

func Reset()

Reset clears all entries. Intended for tests.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL