From fe3c94cd2d1eb99270a029e652fc5494e7106ebe Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Tue, 13 Feb 2018 09:18:42 +0800 Subject: [PATCH] Add Take method, close #1228 --- main.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/main.go b/main.go index d342571d..4bbaadab 100644 --- a/main.go +++ b/main.go @@ -280,6 +280,13 @@ func (s *DB) First(out interface{}, where ...interface{}) *DB { inlineCondition(where...).callCallbacks(s.parent.callbacks.queries).db } +// Take return a record that match given conditions, the order will depend on the database implementation +func (s *DB) Take(out interface{}, where ...interface{}) *DB { + newScope := s.NewScope(out) + newScope.Search.Limit(1) + return newScope.inlineCondition(where...).callCallbacks(s.parent.callbacks.queries).db +} + // Last find last record that match given conditions, order by primary key func (s *DB) Last(out interface{}, where ...interface{}) *DB { newScope := s.NewScope(out)