From d7ef7871a424f1652bf706a0a454a452693400ce Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sun, 10 Mar 2019 19:33:49 +0800 Subject: [PATCH] Fix tests --- callback_query.go | 2 +- main.go | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/callback_query.go b/callback_query.go index 593e5d30..7facc42b 100644 --- a/callback_query.go +++ b/callback_query.go @@ -18,7 +18,7 @@ func queryCallback(scope *Scope) { if _, skip := scope.InstanceGet("gorm:skip_query_callback"); skip { return } - + //we are only preloading relations, dont touch base model if _, skip := scope.InstanceGet("gorm:only_preload"); skip { return diff --git a/main.go b/main.go index 34a6ddc8..f52ba27b 100644 --- a/main.go +++ b/main.go @@ -178,7 +178,13 @@ func (s *DB) SingularTable(enable bool) { func (s *DB) NewScope(value interface{}) *Scope { dbClone := s.clone() dbClone.Value = value - return &Scope{db: dbClone, Search: dbClone.search, Value: value} + scope := &Scope{db: dbClone, Value: value} + if s.search != nil { + scope.Search = s.search.clone() + } else { + scope.Search = &search{} + } + return scope } // QueryExpr returns the query as expr object @@ -298,6 +304,7 @@ func (s *DB) Assign(attrs ...interface{}) *DB { func (s *DB) First(out interface{}, where ...interface{}) *DB { newScope := s.NewScope(out) newScope.Search.Limit(1) + return newScope.Set("gorm:order_by_primary_key", "ASC"). inlineCondition(where...).callCallbacks(s.parent.callbacks.queries).db }