MCPcopy
hub / github.com/go-gorm/gorm / handleAssociationForOwners

Method handleAssociationForOwners

generics.go:776–793  ·  generics.go::setCreateOrUpdateG[T].handleAssociationForOwners

handleAssociationForOwners is a helper function that handles associations for all owners

(base *DB, ctx context.Context, handler func(owner T, association *Association) error, associationName string)

Source from the content-addressed store, hash-verified

774
775// handleAssociationForOwners is a helper function that handles associations for all owners
776func (s setCreateOrUpdateG[T]) handleAssociationForOwners(base *DB, ctx context.Context, handler func(owner T, association *Association) error, associationName string) error {
777 var owners []T
778 if err := base.Find(&owners).Error; err != nil {
779 return err
780 }
781
782 for _, owner := range owners {
783 assoc := base.Session(&Session{NewDB: true, Context: ctx}).Model(&owner).Association(associationName)
784 if assoc.Error != nil {
785 return assoc.Error
786 }
787
788 if err := handler(owner, assoc); err != nil {
789 return err
790 }
791 }
792 return nil
793}
794
795func (s setCreateOrUpdateG[T]) handleAssociation(ctx context.Context, base *DB, op clause.Association) error {
796 assoc := base.Association(op.Association)

Callers 1

Calls 4

ModelMethod · 0.80
SessionMethod · 0.80
FindMethod · 0.65
AssociationMethod · 0.45

Tested by

no test coverage detected