From 0219fb1cc033bda7ed78c90ed933fb3ecdb6f46f Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 19 Dec 2014 11:46:48 +0800 Subject: [PATCH] Don't raise error if no record found when find all --- callback_query.go | 2 +- query_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/callback_query.go b/callback_query.go index f46d6ad4..81b191e7 100644 --- a/callback_query.go +++ b/callback_query.go @@ -76,7 +76,7 @@ func Query(scope *Scope) { } } - if !anyRecordFound { + if !anyRecordFound && !isSlice { scope.Err(RecordNotFound) } } diff --git a/query_test.go b/query_test.go index 09b6c702..a7e3c325 100644 --- a/query_test.go +++ b/query_test.go @@ -146,8 +146,8 @@ func TestSearchWithPlainSQL(t *testing.T) { t.Errorf("Should found 1 users, but got %v", len(users)) } - if !DB.Where("name = ?", "none existing").Find(&[]User{}).RecordNotFound() { - t.Errorf("Should get RecordNotFound error when looking for none existing records") + if DB.Where("name = ?", "none existing").Find(&[]User{}).RecordNotFound() { + t.Errorf("Should not get RecordNotFound error when looking for none existing records") } }