Fix tests

This commit is contained in:
Jinzhu 2019-03-10 19:33:49 +08:00
parent f3a0fc1566
commit d7ef7871a4
2 changed files with 9 additions and 2 deletions

View File

@ -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

View File

@ -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
}