allow SkipHooks when preload & save associations

This commit is contained in:
Jinzhu 2020-11-20 16:56:52 +08:00
parent dec8748512
commit 6186a4daa7
2 changed files with 2 additions and 2 deletions

View File

@ -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 { if len(selects) > 0 {
tx = tx.Select(selects) tx = tx.Select(selects)

View File

@ -13,7 +13,7 @@ func preload(db *gorm.DB, rels []*schema.Relationship, conds []interface{}) {
var ( var (
reflectValue = db.Statement.ReflectValue reflectValue = db.Statement.ReflectValue
rel = rels[len(rels)-1] 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 relForeignKeys []string
relForeignFields []*schema.Field relForeignFields []*schema.Field
foreignFields []*schema.Field foreignFields []*schema.Field