From bab148f90cf31dcd8e8f78e8327c6dc13b4e61af Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 9 Jun 2014 08:17:20 +0800 Subject: [PATCH] Fix RowsAffected tests --- callback_create.go | 4 +++- main_test.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/callback_create.go b/callback_create.go index b17f596a..8276f0d2 100644 --- a/callback_create.go +++ b/callback_create.go @@ -60,7 +60,9 @@ func Create(scope *Scope) { } } } else { - scope.Err(scope.DB().QueryRow(scope.Sql, scope.SqlVars...).Scan(&id)) + if scope.Err(scope.DB().QueryRow(scope.Sql, scope.SqlVars...).Scan(&id)) == nil { + scope.db.RowsAffected = 1 + } } if !scope.HasError() { diff --git a/main_test.go b/main_test.go index 92d5a7e0..6d0d17e1 100644 --- a/main_test.go +++ b/main_test.go @@ -1111,7 +1111,7 @@ func TestUpdate(t *testing.T) { var animals []Animal db.Find(&animals) - if count := db.Model(Animal{}).Update("CreatedAt", time.Now()).RowsAffected; count != int64(len(animals)) { + if count := db.Model(Animal{}).Update("CreatedAt", time.Now().Add(2*time.Hour)).RowsAffected; count != int64(len(animals)) { t.Error("RowsAffected should be correct when do batch update") } }