association

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2026 License: AGPL-3.0 Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Association

type Association struct {
	// contains filtered or unexported fields
}

Association represents a model association.

func NewAssociation

func NewAssociation(query contractsorm.Query, model any, association string) *Association

NewAssociation creates a new Association instance.

func (*Association) Append

func (a *Association) Append(values ...any) error

Append appending a model to the association.

func (*Association) AssociationName

func (a *Association) AssociationName() string

AssociationName returns the association name.

func (*Association) Clear

func (a *Association) Clear() error

Clear clears the association.

func (*Association) Count

func (a *Association) Count() int64

Count returns the number of records in the association.

func (*Association) Delete

func (a *Association) Delete(values ...any) error

Delete deletes the given value from the association.

func (*Association) Find

func (a *Association) Find(out any, conds ...any) error

Find finds records that match given conditions.

func (*Association) Model

func (a *Association) Model() any

Model returns the model instance.

func (*Association) Query

func (a *Association) Query() contractsorm.Query

Query returns the underlying query instance.

func (*Association) Replace

func (a *Association) Replace(values ...any) error

Replace replaces the association with the given value.

type BelongsTo

type BelongsTo struct {
	*Association
	// contains filtered or unexported fields
}

BelongsTo represents a belongs-to relationship.

func NewBelongsTo

func NewBelongsTo(query contractsorm.Query, model any, association, foreignKey, otherKey string) *BelongsTo

NewBelongsTo creates a new BelongsTo association.

func (*BelongsTo) Append

func (b *BelongsTo) Append(values ...any) error

Append sets the foreign key to associate the model.

func (*BelongsTo) Clear

func (b *BelongsTo) Clear() error

Clear clears the association by setting the foreign key to nil.

func (*BelongsTo) Count

func (b *BelongsTo) Count() int64

Count returns 1 if the association exists, 0 otherwise.

func (*BelongsTo) Delete

func (b *BelongsTo) Delete(values ...any) error

Delete clears the association by setting the foreign key to nil.

func (*BelongsTo) Find

func (b *BelongsTo) Find(out any, conds ...any) error

Find loads the associated model for a belongs-to relationship.

func (*BelongsTo) Replace

func (b *BelongsTo) Replace(values ...any) error

Replace replaces the current association with the given value.

type HasMany

type HasMany struct {
	*Association
	// contains filtered or unexported fields
}

HasMany represents a has-many relationship.

func NewHasMany

func NewHasMany(query contractsorm.Query, model any, association, foreignKey, localKey string) *HasMany

NewHasMany creates a new HasMany association.

func (*HasMany) Append

func (h *HasMany) Append(values ...any) error

Append appends models to the association.

func (*HasMany) Clear

func (h *HasMany) Clear() error

Clear clears the association by setting the foreign key to null for all related models.

func (*HasMany) Count

func (h *HasMany) Count() int64

Count returns the number of records in the association.

func (*HasMany) Delete

func (h *HasMany) Delete(values ...any) error

Delete removes the given values from the association.

func (*HasMany) Find

func (h *HasMany) Find(out any, conds ...any) error

Find loads the associated models for a has-many relationship.

func (*HasMany) Replace

func (h *HasMany) Replace(values ...any) error

Replace replaces the current association with the given values.

type HasOne

type HasOne struct {
	*Association
	// contains filtered or unexported fields
}

HasOne represents a has-one relationship.

func NewHasOne

func NewHasOne(query contractsorm.Query, model any, association, foreignKey, localKey string) *HasOne

NewHasOne creates a new HasOne association.

func (*HasOne) Append

func (h *HasOne) Append(values ...any) error

Append sets the foreign key to associate the model.

func (*HasOne) Clear

func (h *HasOne) Clear() error

Clear clears the association by setting the foreign key to null.

func (*HasOne) Count

func (h *HasOne) Count() int64

Count returns 1 if the association exists, 0 otherwise.

func (*HasOne) Delete

func (h *HasOne) Delete(values ...any) error

Delete removes the given value from the association.

func (*HasOne) Find

func (h *HasOne) Find(out any, conds ...any) error

Find loads the associated model for a has-one relationship.

func (*HasOne) Replace

func (h *HasOne) Replace(values ...any) error

Replace replaces the current association with the given value.

type PolymorphicBelongsTo added in v0.6.0

type PolymorphicBelongsTo struct {
	*Association
	// contains filtered or unexported fields
}

PolymorphicBelongsTo represents a polymorphic belongs-to relationship. This allows a model to belong to multiple different model types. Example: A Comment can belong to a Post or a Video.

func NewPolymorphicBelongsTo added in v0.6.0

func NewPolymorphicBelongsTo(query contractsorm.Query, model any, association, polymorphicID, polymorphicType string) *PolymorphicBelongsTo

NewPolymorphicBelongsTo creates a new PolymorphicBelongsTo association.

func (*PolymorphicBelongsTo) Append added in v0.6.0

func (p *PolymorphicBelongsTo) Append(values ...any) error

Append sets the polymorphic fields to associate the model.

func (*PolymorphicBelongsTo) Clear added in v0.6.0

func (p *PolymorphicBelongsTo) Clear() error

Clear clears the association by setting the polymorphic fields to nil.

func (*PolymorphicBelongsTo) Count added in v0.6.0

func (p *PolymorphicBelongsTo) Count() int64

Count returns 1 if the association exists, 0 otherwise.

func (*PolymorphicBelongsTo) Delete added in v0.6.0

func (p *PolymorphicBelongsTo) Delete(values ...any) error

Delete clears the association by setting the polymorphic fields to nil. The values parameter is validated to ensure the provided value matches the current association.

func (*PolymorphicBelongsTo) Find added in v0.6.0

func (p *PolymorphicBelongsTo) Find(out any, conds ...any) error

Find loads the associated model for a polymorphic belongs-to relationship.

func (*PolymorphicBelongsTo) Replace added in v0.6.0

func (p *PolymorphicBelongsTo) Replace(values ...any) error

Replace replaces the current association with the given value.

type PolymorphicHasMany added in v0.6.0

type PolymorphicHasMany struct {
	*Association
	// contains filtered or unexported fields
}

PolymorphicHasMany represents a polymorphic has-many relationship. This allows a model to have many related models that can belong to multiple different model types. Example: A Post can have many Comments, and a Video can also have many Comments.

func NewPolymorphicHasMany added in v0.6.0

func NewPolymorphicHasMany(query contractsorm.Query, model any, association, polymorphicID, polymorphicType, localKey string) *PolymorphicHasMany

NewPolymorphicHasMany creates a new PolymorphicHasMany association.

func (*PolymorphicHasMany) Append added in v0.6.0

func (p *PolymorphicHasMany) Append(values ...any) error

Append appends models to the polymorphic association.

func (*PolymorphicHasMany) Clear added in v0.6.0

func (p *PolymorphicHasMany) Clear() error

Clear clears the association by setting the polymorphic fields to null for all related models.

func (*PolymorphicHasMany) Count added in v0.6.0

func (p *PolymorphicHasMany) Count() int64

Count returns the number of records in the association.

func (*PolymorphicHasMany) Delete added in v0.6.0

func (p *PolymorphicHasMany) Delete(values ...any) error

Delete removes the given values from the association.

func (*PolymorphicHasMany) Find added in v0.6.0

func (p *PolymorphicHasMany) Find(out any, conds ...any) error

Find loads the associated models for a polymorphic has-many relationship.

func (*PolymorphicHasMany) Replace added in v0.6.0

func (p *PolymorphicHasMany) Replace(values ...any) error

Replace replaces the current association with the given values.

Jump to

Keyboard shortcuts

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