Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MorphAlias ¶
MorphAlias returns the alias registered for the given model's underlying type. Useful at insert time when writing the value of a `*_type` column from a Go value.
func MorphMap ¶
MorphMap registers polymorphic aliases. Each entry maps an alias (the value stored in a `*_type` column) to a sample model instance from which the registry derives the underlying Go type.
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.
orm.MorphMap(map[string]any{
"post": &Post{},
"video": &Video{},
})
Models that implement orm.ModelWithMorphClass take precedence over the registry.
func MorphedModel ¶
MorphedModel returns a fresh pointer to a new instance of the model registered under alias, or nil if no model is registered. Used by the MorphTo loader to allocate the right Go type for a row whose `*_type` column contains alias.
Types ¶
type DeletedAt ¶
DeletedAt records when a row was soft deleted. It is the type orm.SoftDeletes carries.
It is laid out exactly like database/sql.NullTime — Valid reports whether the row is soft deleted, and Time holds the moment it happened — so scanning and binding behave the same as the GORM type it replaces, and it can be converted to sql.NullTime rather than reimplementing the scanner.
The clause interfaces gorm.DeletedAt also implemented are deliberately absent. They were how GORM learned to filter soft-deleted rows and to turn a delete into an update; the framework now builds that predicate itself, so this type only has to carry the value.
func (DeletedAt) IsZero ¶
IsZero reports whether no deletion time is recorded, which is how a soft-delete field is recognised as carrying a value.
func (DeletedAt) MarshalJSON ¶
MarshalJSON renders the deletion time, or null when the row was not soft deleted.
func (*DeletedAt) UnmarshalJSON ¶
UnmarshalJSON restores the deletion time, reading null as "not soft deleted".
type Model ¶
type Model struct {
Timestamps
ID uint `gorm:"primaryKey" json:"id"`
}
Model is the base model for all models in the application.
type SoftDeletes ¶
type SoftDeletes struct {
DeletedAt DeletedAt `gorm:"column:deleted_at" json:"deleted_at"`
}
SoftDeletes is used to add soft delete functionality to a model.
The field carries the framework's own type, so the ORM builds the soft-delete predicate and the delete rewrite itself instead of asking GORM to.