From db23976bb543382f19268fed9e2ff40868b64125 Mon Sep 17 00:00:00 2001 From: hhniao <12420958+hhniao@users.noreply.github.com> Date: Fri, 1 Sep 2023 14:42:57 +0800 Subject: [PATCH] Update associations.go fix clause.OnConflict{DoNothing: true} --- callbacks/associations.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/callbacks/associations.go b/callbacks/associations.go index f3cd464a..8fdfa0ae 100644 --- a/callbacks/associations.go +++ b/callbacks/associations.go @@ -358,6 +358,12 @@ func SaveAfterAssociations(create bool) func(db *gorm.DB) { } func onConflictOption(stmt *gorm.Statement, s *schema.Schema, defaultUpdatingColumns []string) (onConflict clause.OnConflict) { + if sc, ok := stmt.Clauses["ON CONFLICT"]; ok { + if oc, oo := sc.Expression.(clause.OnConflict);oo && oc.DoNothing { + onConflict.DoNothing = true + return + } + } if len(defaultUpdatingColumns) > 0 || stmt.DB.FullSaveAssociations { onConflict.Columns = make([]clause.Column, 0, len(s.PrimaryFieldDBNames)) for _, dbName := range s.PrimaryFieldDBNames {