diff --git a/main.go b/main.go index 17e3246c..8e85f754 100644 --- a/main.go +++ b/main.go @@ -165,7 +165,11 @@ func (s *DB) Scan(dest interface{}) *DB { func (s *DB) FirstOrInit(out interface{}, where ...interface{}) *DB { c := s.clone() - if c.First(out, where...).Error == RecordNotFound { + r := c.First(out, where...) + if r.Error != nil { + if !r.RecordNotFound() { + return r + } c.NewScope(out).inlineCondition(where...).initialize() } else { c.NewScope(out).updatedAttrsWithValues(convertInterfaceToMap(s.search.AssignAttrs), false) @@ -175,7 +179,11 @@ func (s *DB) FirstOrInit(out interface{}, where ...interface{}) *DB { func (s *DB) FirstOrCreate(out interface{}, where ...interface{}) *DB { c := s.clone() - if c.First(out, where...).Error == RecordNotFound { + r := c.First(out, where...) + if r.Error != nil { + if !r.RecordNotFound() { + return r + } c.NewScope(out).inlineCondition(where...).initialize().callCallbacks(s.parent.callback.creates) } else if len(s.search.AssignAttrs) > 0 { c.NewScope(out).Set("gorm:update_interface", s.search.AssignAttrs).callCallbacks(s.parent.callback.updates)