From 6186a4daa7ad61fdfb7750db68ba30c3391cc614 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 20 Nov 2020 16:56:52 +0800 Subject: [PATCH] allow SkipHooks when preload & save associations --- callbacks/associations.go | 2 +- callbacks/preload.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/callbacks/associations.go b/callbacks/associations.go index 0fa47868..e6669600 100644 --- a/callbacks/associations.go +++ b/callbacks/associations.go @@ -359,7 +359,7 @@ func saveAssociations(db *gorm.DB, rel *schema.Relationship, values interface{}, } } - tx := db.Session(&gorm.Session{NewDB: true}).Clauses(onConflict) + tx := db.Session(&gorm.Session{NewDB: true}).Clauses(onConflict).Session(&gorm.Session{SkipHooks: db.Statement.SkipHooks}) if len(selects) > 0 { tx = tx.Select(selects) diff --git a/callbacks/preload.go b/callbacks/preload.go index c2304af8..682427c9 100644 --- a/callbacks/preload.go +++ b/callbacks/preload.go @@ -13,7 +13,7 @@ func preload(db *gorm.DB, rels []*schema.Relationship, conds []interface{}) { var ( reflectValue = db.Statement.ReflectValue rel = rels[len(rels)-1] - tx = db.Session(&gorm.Session{NewDB: true, SkipHooks: db.Statement.SkipHooks}) + tx = db.Session(&gorm.Session{NewDB: true}).Model(nil).Session(&gorm.Session{SkipHooks: db.Statement.SkipHooks}) relForeignKeys []string relForeignFields []*schema.Field foreignFields []*schema.Field