From 549d7a8af26792ec04d9c57cb4c77751c8f9c59e Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 28 Jan 2014 09:30:30 +0800 Subject: [PATCH] make first, last works with plugin system --- main.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index b185c379..f2ad76e2 100644 --- a/main.go +++ b/main.go @@ -110,12 +110,17 @@ func (s *DB) Unscoped() *DB { } func (s *DB) First(out interface{}, where ...interface{}) *DB { - return s.clone().do(out).where(where...).first().db + scope := s.clone().NewScope(out) + scope.Search = scope.Search.clone().order(scope.PrimaryKey()).limit(1) + return scope.Set("gorm:inline_condition", where).callCallbacks(s.parent.callback.queries).db } func (s *DB) Last(out interface{}, where ...interface{}) *DB { - return s.clone().do(out).where(where...).last().db + scope := s.clone().NewScope(out) + scope.Search = scope.Search.clone().order(scope.PrimaryKey() + " DESC").limit(1) + return scope.Set("gorm:inline_condition", where).callCallbacks(s.parent.callback.queries).db } + func (s *DB) Find(out interface{}, where ...interface{}) *DB { return s.clone().NewScope(out).Set("gorm:inline_condition", where).callCallbacks(s.parent.callback.queries).db }