style: prepose error judgement

This commit is contained in:
riverchu 2021-09-03 23:09:20 +08:00 committed by Jinzhu
parent a89d4d8fd5
commit 1d9e563023
1 changed files with 26 additions and 24 deletions

View File

@ -51,7 +51,10 @@ func BeforeUpdate(db *gorm.DB) {
} }
func Update(db *gorm.DB) { func Update(db *gorm.DB) {
if db.Error == nil { if db.Error != nil {
return
}
if db.Statement.Schema != nil && !db.Statement.Unscoped { if db.Statement.Schema != nil && !db.Statement.Unscoped {
for _, c := range db.Statement.Schema.UpdateClauses { for _, c := range db.Statement.Schema.UpdateClauses {
db.Statement.AddClause(c) db.Statement.AddClause(c)
@ -84,7 +87,6 @@ func Update(db *gorm.DB) {
} }
} }
} }
}
func AfterUpdate(db *gorm.DB) { func AfterUpdate(db *gorm.DB) {
if db.Error == nil && db.Statement.Schema != nil && !db.Statement.SkipHooks && (db.Statement.Schema.AfterSave || db.Statement.Schema.AfterUpdate) { if db.Error == nil && db.Statement.Schema != nil && !db.Statement.SkipHooks && (db.Statement.Schema.AfterSave || db.Statement.Schema.AfterUpdate) {