forked from mirror/gorm
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:
parent
712c465560
commit
781a818390
2
main.go
2
main.go
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue