Remove ErrRecordNotFound error from log when using Save

This commit is contained in:
Jinzhu 2022-04-14 10:51:39 +08:00
parent ce53ea53ee
commit d421c67ef5
2 changed files with 2 additions and 2 deletions

View File

@ -105,7 +105,7 @@ func (db *DB) Save(value interface{}) (tx *DB) {
if tx.Error == nil && tx.RowsAffected == 0 && !tx.DryRun && !selectedUpdate {
result := reflect.New(tx.Statement.Schema.ModelType).Interface()
if err := tx.Session(&Session{}).Take(result).Error; errors.Is(err, ErrRecordNotFound) {
if result := tx.Session(&Session{}).Limit(1).Find(result); result.RowsAffected == 0 {
return tx.Create(value)
}
}

View File

@ -8,7 +8,7 @@ require (
github.com/jinzhu/now v1.1.5
github.com/lib/pq v1.10.5
github.com/mattn/go-sqlite3 v1.14.12 // indirect
golang.org/x/crypto v0.0.0-20220408190544-5352b0902921 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
gorm.io/driver/mysql v1.3.3
gorm.io/driver/postgres v1.3.4
gorm.io/driver/sqlite v1.3.1