fix save err when specify a table name

s.New() will clear all search conditions and search value,when I use Table() to set a table name. Then FirstOrCreate() will use struct name as my database table name,so It doesn't work.
This commit is contained in:
Momo733 2019-04-13 14:23:35 +08:00 committed by GitHub
parent efcabc8be3
commit 1c62bf1e57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -444,7 +444,7 @@ func (s *DB) Save(value interface{}) *DB {
if !scope.PrimaryKeyZero() {
newDB := scope.callCallbacks(s.parent.callbacks.updates).db
if newDB.Error == nil && newDB.RowsAffected == 0 {
return s.New().FirstOrCreate(value)
return s.FirstOrCreate(value)
}
return newDB
}