From a29ac54e484be3c027d28090b59118be79dd4864 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 28 Oct 2014 17:18:11 +0800 Subject: [PATCH] Limit condition should not be inherited by following queries --- main.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 3a6eb5c1..14a76b19 100644 --- a/main.go +++ b/main.go @@ -166,12 +166,18 @@ func (s *DB) Assign(attrs ...interface{}) *DB { } func (s *DB) First(out interface{}, where ...interface{}) *DB { - return s.clone().Limit(1).NewScope(out).InstanceSet("gorm:order_by_primary_key", "ASC"). + newScope := s.clone().NewScope(out) + newScope.Search = newScope.Search.clone() + newScope.Search.limit(1) + return newScope.InstanceSet("gorm:order_by_primary_key", "ASC"). inlineCondition(where...).callCallbacks(s.parent.callback.queries).db } func (s *DB) Last(out interface{}, where ...interface{}) *DB { - return s.clone().Limit(1).NewScope(out).InstanceSet("gorm:order_by_primary_key", "DESC"). + newScope := s.clone().NewScope(out) + newScope.Search = newScope.Search.clone() + newScope.Search.limit(1) + return newScope.InstanceSet("gorm:order_by_primary_key", "DESC"). inlineCondition(where...).callCallbacks(s.parent.callback.queries).db }