fix: Save not use soft_delete
This commit is contained in:
parent
300a23fc31
commit
e78c92378b
@ -73,6 +73,13 @@ func Update(config *Config) func(db *gorm.DB) {
|
||||
} else if _, ok := db.Statement.Clauses["SET"]; !ok {
|
||||
return
|
||||
}
|
||||
|
||||
if _, ok := db.Statement.Clauses["WHERE"]; ok && db.Statement.Schema != nil && !db.Statement.Unscoped {
|
||||
for _, c := range db.Statement.Schema.UpdateClauses {
|
||||
db.Statement.AddClause(c)
|
||||
}
|
||||
}
|
||||
|
||||
db.Statement.Build(db.Statement.BuildClauses...)
|
||||
}
|
||||
|
||||
|
@ -645,7 +645,13 @@ func TestSave(t *testing.T) {
|
||||
|
||||
dryDB := DB.Session(&gorm.Session{DryRun: true})
|
||||
stmt := dryDB.Save(&user).Statement
|
||||
if !regexp.MustCompile("WHERE .id. = [^ ]+$").MatchString(stmt.SQL.String()) {
|
||||
if !regexp.MustCompile(`.id. = .* AND .users.\..deleted_at. IS NULL`).MatchString(stmt.SQL.String()) {
|
||||
t.Fatalf("invalid updating SQL, got %v", stmt.SQL.String())
|
||||
}
|
||||
|
||||
dryDB = DB.Session(&gorm.Session{DryRun: true})
|
||||
stmt = dryDB.Unscoped().Save(&user).Statement
|
||||
if !regexp.MustCompile(`WHERE .id. = [^ ]+$`).MatchString(stmt.SQL.String()) {
|
||||
t.Fatalf("invalid updating SQL, got %v", stmt.SQL.String())
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user