Documentation
¶
Index ¶
- type Association
- func (a *Association) Append(values ...any) error
- func (a *Association) AssociationName() string
- func (a *Association) Clear() error
- func (a *Association) Count() int64
- func (a *Association) Delete(values ...any) error
- func (a *Association) Find(out any, conds ...any) error
- func (a *Association) Model() any
- func (a *Association) Query() contractsorm.Query
- func (a *Association) Replace(values ...any) error
- type BelongsTo
- type HasMany
- type HasOne
- type PolymorphicBelongsTo
- func (p *PolymorphicBelongsTo) Append(values ...any) error
- func (p *PolymorphicBelongsTo) Clear() error
- func (p *PolymorphicBelongsTo) Count() int64
- func (p *PolymorphicBelongsTo) Delete(values ...any) error
- func (p *PolymorphicBelongsTo) Find(out any, conds ...any) error
- func (p *PolymorphicBelongsTo) Replace(values ...any) error
- type PolymorphicHasMany
- func (p *PolymorphicHasMany) Append(values ...any) error
- func (p *PolymorphicHasMany) Clear() error
- func (p *PolymorphicHasMany) Count() int64
- func (p *PolymorphicHasMany) Delete(values ...any) error
- func (p *PolymorphicHasMany) Find(out any, conds ...any) error
- func (p *PolymorphicHasMany) Replace(values ...any) error
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) 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) 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.
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) Clear ¶
Clear clears the association by setting the foreign key to null for all related models.
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.
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.