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 Jinzhu
parent 712c465560
commit 781a818390
1 changed files with 1 additions and 1 deletions

View File

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