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

Method handleAssociationCreate

generics.go:759–773  ·  view source on GitHub ↗
(ctx context.Context, base *DB, op clause.Association)

Source from the content-addressed store, hash-verified

757}
758
759func (s setCreateOrUpdateG[T]) handleAssociationCreate(ctx context.Context, base *DB, op clause.Association) error {
760 if len(op.Set) > 0 {
761 return s.handleAssociationForOwners(base, ctx, func(owner T, assoc *Association) error {
762 data := make(map[string]interface{}, len(op.Set))
763 for _, a := range op.Set {
764 data[a.Column.Name] = a.Value
765 }
766 return assoc.Append(data)
767 }, op.Association)
768 }
769
770 return s.handleAssociationForOwners(base, ctx, func(owner T, assoc *Association) error {
771 return assoc.Append(op.Values...)
772 }, op.Association)
773}
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 {

Callers 1

Calls 2

AppendMethod · 0.80

Tested by

no test coverage detected