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)
| 774 | |
| 775 | // handleAssociationForOwners is a helper function that handles associations for all owners |
| 776 | func (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 | |
| 795 | func (s setCreateOrUpdateG[T]) handleAssociation(ctx context.Context, base *DB, op clause.Association) error { |
| 796 | assoc := base.Association(op.Association) |
no test coverage detected