Skip to content

Commit d421c67

Browse files
committed
Remove ErrRecordNotFound error from log when using Save
1 parent ce53ea5 commit d421c67

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

finisher_api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func (db *DB) Save(value interface{}) (tx *DB) {
105105

106106
if tx.Error == nil && tx.RowsAffected == 0 && !tx.DryRun && !selectedUpdate {
107107
result := reflect.New(tx.Statement.Schema.ModelType).Interface()
108-
if err := tx.Session(&Session{}).Take(result).Error; errors.Is(err, ErrRecordNotFound) {
108+
if result := tx.Session(&Session{}).Limit(1).Find(result); result.RowsAffected == 0 {
109109
return tx.Create(value)
110110
}
111111
}

tests/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/jinzhu/now v1.1.5
99
github.com/lib/pq v1.10.5
1010
github.com/mattn/go-sqlite3 v1.14.12 // indirect
11-
golang.org/x/crypto v0.0.0-20220408190544-5352b0902921 // indirect
11+
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
1212
gorm.io/driver/mysql v1.3.3
1313
gorm.io/driver/postgres v1.3.4
1414
gorm.io/driver/sqlite v1.3.1

0 commit comments

Comments
 (0)