mirror of https://github.com/go-gorm/gorm.git
Fix FirstOrXXX access invalid memory address
*DB is cloned, we should ALWAYS use the cloned pointer instead of original one.
This commit is contained in:
parent
ede940e82d
commit
f1decc2c3e
6
main.go
6
main.go
|
@ -247,7 +247,7 @@ func (s *DB) FirstOrInit(out interface{}, where ...interface{}) *DB {
|
|||
}
|
||||
c.NewScope(out).inlineCondition(where...).initialize()
|
||||
} else {
|
||||
c.NewScope(out).updatedAttrsWithValues(convertInterfaceToMap(s.search.assignAttrs), false)
|
||||
c.NewScope(out).updatedAttrsWithValues(convertInterfaceToMap(c.search.assignAttrs), false)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
@ -258,9 +258,9 @@ func (s *DB) FirstOrCreate(out interface{}, where ...interface{}) *DB {
|
|||
if !result.RecordNotFound() {
|
||||
return result
|
||||
}
|
||||
c.AddError(c.NewScope(out).inlineCondition(where...).initialize().callCallbacks(s.parent.callback.creates).db.Error)
|
||||
c.AddError(c.NewScope(out).inlineCondition(where...).initialize().callCallbacks(c.parent.callback.creates).db.Error)
|
||||
} else if len(c.search.assignAttrs) > 0 {
|
||||
c.AddError(c.NewScope(out).InstanceSet("gorm:update_interface", s.search.assignAttrs).callCallbacks(s.parent.callback.updates).db.Error)
|
||||
c.AddError(c.NewScope(out).InstanceSet("gorm:update_interface", c.search.assignAttrs).callCallbacks(c.parent.callback.updates).db.Error)
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue