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") } }