From 4c815fd2cc489fb440d740e58439c2cfe402e34d Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Thu, 12 Mar 2015 12:01:53 +0800 Subject: [PATCH] Add add limit 1 for Find automatically --- callback_query.go | 2 -- query_test.go | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/callback_query.go b/callback_query.go index e7e388b4..2c16610c 100644 --- a/callback_query.go +++ b/callback_query.go @@ -33,8 +33,6 @@ func Query(scope *Scope) { isPtr = true destType = destType.Elem() } - } else { - scope.Search = scope.Search.clone().limit(1) } scope.prepareQuerySql() diff --git a/query_test.go b/query_test.go index be309ed7..684c6f1e 100644 --- a/query_test.go +++ b/query_test.go @@ -16,10 +16,10 @@ func TestFirstAndLast(t *testing.T) { var user1, user2, user3, user4 User DB.First(&user1) - DB.Order("id").Find(&user2) + DB.Order("id").Limit(1).Find(&user2) DB.Last(&user3) - DB.Order("id desc").Find(&user4) + DB.Order("id desc").Limit(1).Find(&user4) if user1.Id != user2.Id || user3.Id != user4.Id { t.Errorf("First and Last should by order by primary key") } @@ -41,10 +41,10 @@ func TestFirstAndLastWithNoStdPrimaryKey(t *testing.T) { var animal1, animal2, animal3, animal4 Animal DB.First(&animal1) - DB.Order("counter").Find(&animal2) + DB.Order("counter").Limit(1).Find(&animal2) DB.Last(&animal3) - DB.Order("counter desc").Find(&animal4) + DB.Order("counter desc").Limit(1).Find(&animal4) if animal1.Counter != animal2.Counter || animal3.Counter != animal4.Counter { t.Errorf("First and Last should work correctly") }