diff --git a/finisher_api.go b/finisher_api.go index 434f0e22..72453b1d 100644 --- a/finisher_api.go +++ b/finisher_api.go @@ -389,7 +389,3 @@ func (db *DB) Exec(sql string, values ...interface{}) (tx *DB) { tx.callbacks.Raw().Execute(tx) return } - -func (db *DB) RecordNotFound() bool { - return errors.Is(db.Error, ErrRecordNotFound) -} diff --git a/tests/delete_test.go b/tests/delete_test.go index 66c396d1..b853a9d3 100644 --- a/tests/delete_test.go +++ b/tests/delete_test.go @@ -52,13 +52,13 @@ func TestInlineCondDelete(t *testing.T) { if DB.Delete(&User{}, user1.ID).Error != nil { t.Errorf("No error should happen when delete a record") - } else if !DB.Where("name = ?", user1.Name).First(&User{}).RecordNotFound() { + } else if err := DB.Where("name = ?", user1.Name).First(&User{}).Error; !errors.Is(err, gorm.ErrRecordNotFound) { t.Errorf("User can't be found after delete") } if err := DB.Delete(&User{}, "name = ?", user2.Name).Error; err != nil { t.Errorf("No error should happen when delete a record, err=%s", err) - } else if !DB.Where("name = ?", user2.Name).First(&User{}).RecordNotFound() { + } else if err := DB.Where("name = ?", user2.Name).First(&User{}).Error; !errors.Is(err, gorm.ErrRecordNotFound) { t.Errorf("User can't be found after delete") } } diff --git a/tests/soft_delete_test.go b/tests/soft_delete_test.go index c632c753..b6dabe06 100644 --- a/tests/soft_delete_test.go +++ b/tests/soft_delete_test.go @@ -1,8 +1,10 @@ package tests_test import ( + "errors" "testing" + "gorm.io/gorm" . "gorm.io/gorm/utils/tests" ) @@ -22,7 +24,7 @@ func TestSoftDelete(t *testing.T) { } DB.Unscoped().Delete(&user) - if !DB.Unscoped().First(&User{}, "name = ?", user.Name).RecordNotFound() { + if err := DB.Unscoped().First(&User{}, "name = ?", user.Name).Error; !errors.Is(err, gorm.ErrRecordNotFound) { t.Errorf("Can't find permanently deleted record") } } diff --git a/tests/update_test.go b/tests/update_test.go index 220d3e76..d56e3f76 100644 --- a/tests/update_test.go +++ b/tests/update_test.go @@ -149,7 +149,7 @@ func TestUpdates(t *testing.T) { DB.Table("users").Where("name in ?", []string{users[1].Name}).Updates(User{Name: "updates_02_newname"}) var user3 User - if DB.First(&user3, "name = ?", "updates_02_newname").RecordNotFound() { + if err := DB.First(&user3, "name = ?", "updates_02_newname").Error; err != nil { t.Errorf("User2's name should be updated") } AssertEqual(t, user2.UpdatedAt, user3.UpdatedAt) diff --git a/tests/upsert_test.go b/tests/upsert_test.go index 311b7136..e9ba54e3 100644 --- a/tests/upsert_test.go +++ b/tests/upsert_test.go @@ -171,11 +171,11 @@ func TestFindOrCreate(t *testing.T) { } DB.Where(&User{Name: "find or create embedded struct"}).Assign(User{Age: 44, Account: Account{Number: "1231231231"}, Pets: []*Pet{{Name: "first_or_create_pet1"}, {Name: "first_or_create_pet2"}}}).FirstOrCreate(&user8) - if DB.Where("name = ?", "first_or_create_pet1").First(&Pet{}).RecordNotFound() { + if err := DB.Where("name = ?", "first_or_create_pet1").First(&Pet{}).Error; err != nil { t.Errorf("has many association should be saved") } - if DB.Where("number = ?", "1231231231").First(&Account{}).RecordNotFound() { + if err := DB.Where("number = ?", "1231231231").First(&Account{}).Error; err != nil { t.Errorf("belongs to association should be saved") } }