diff --git a/main.go b/main.go index 49686e23..3fd42ff2 100644 --- a/main.go +++ b/main.go @@ -77,6 +77,11 @@ func (s *DB) DB() *sql.DB { return s.db.(*sql.DB) } +func (s *DB) New() *DB { + s.search = nil + return s.clone() +} + // Return the underlying sql.DB or sql.Tx instance. // Use of this method is discouraged. It's mainly intended to allow // coexistence with legacy non-GORM code. diff --git a/main_private.go b/main_private.go index 2353b43f..6dd5c00b 100644 --- a/main_private.go +++ b/main_private.go @@ -22,11 +22,6 @@ func (s *DB) clone() *DB { return &db } -func (s *DB) new() *DB { - s.search = nil - return s.clone() -} - func (s *DB) err(err error) error { if err != nil { if err != RecordNotFound { diff --git a/scope.go b/scope.go index 8423363c..daf3acec 100644 --- a/scope.go +++ b/scope.go @@ -55,7 +55,7 @@ func (scope *Scope) New(value interface{}) *Scope { // NewDB create a new DB without search information func (scope *Scope) NewDB() *DB { - return scope.db.new() + return scope.db.New() } // DB get *sql.DB @@ -191,13 +191,13 @@ func (scope *Scope) CallMethod(name string) { case func(s *Scope): f(scope) case func(s *DB): - f(scope.db.new()) + f(scope.db.New()) case func() error: scope.Err(f()) case func(s *Scope) error: scope.Err(f(scope)) case func(s *DB) error: - scope.Err(f(scope.db.new())) + scope.Err(f(scope.db.New())) default: scope.Err(errors.New(fmt.Sprintf("unsupported function %v", name))) }