Update associations.go

fix  clause.OnConflict{DoNothing: true}
This commit is contained in:
hhniao 2023-09-01 14:42:57 +08:00 committed by GitHub
parent e57e5d8884
commit db23976bb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) { 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 { if len(defaultUpdatingColumns) > 0 || stmt.DB.FullSaveAssociations {
onConflict.Columns = make([]clause.Column, 0, len(s.PrimaryFieldDBNames)) onConflict.Columns = make([]clause.Column, 0, len(s.PrimaryFieldDBNames))
for _, dbName := range s.PrimaryFieldDBNames { for _, dbName := range s.PrimaryFieldDBNames {