From c9f112c1132dbbab3af5c8a0024e5f33f4d74b65 Mon Sep 17 00:00:00 2001 From: Roy Reznik Date: Wed, 6 May 2020 00:32:55 +0300 Subject: [PATCH] Fixed tests --- callback_update.go | 4 ++-- callbacks_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/callback_update.go b/callback_update.go index 0c67c8fd..13d3c3bf 100644 --- a/callback_update.go +++ b/callback_update.go @@ -75,8 +75,8 @@ func updateCallback(scope *Scope) { } else { for _, field := range scope.Fields() { if scope.changeableField(field) { - if !field.IsPrimaryKey && field.IsNormal && (!field.IsBlank || field.HasDefaultValue) { - if !field.IsForeignKey || !field.IsBlank || !field.HasDefaultValue { + if !field.IsPrimaryKey && field.IsNormal && (!field.IsBlank || field.HasDefaultValue || field.IsForeignKey) { + if !field.IsForeignKey || !field.IsBlank || field.HasDefaultValue { sqls = append(sqls, fmt.Sprintf("%v = %v", scope.Quote(field.DBName), scope.AddToVars(field.Field.Interface()))) } } else if relationship := field.Relationship; relationship != nil && relationship.Kind == "belongs_to" { diff --git a/callbacks_test.go b/callbacks_test.go index bebd0e38..62cb1660 100644 --- a/callbacks_test.go +++ b/callbacks_test.go @@ -98,12 +98,12 @@ func TestRunCallbacks(t *testing.T) { } DB.Where("Code = ?", "unique_code").First(&p) - if !reflect.DeepEqual(p.GetCallTimes(), []int64{1, 2, 1, 1, 0, 0, 0, 0, 2}) { + if !reflect.DeepEqual(p.GetCallTimes(), []int64{1, 2, 0, 1, 0, 0, 0, 0, 2}) { t.Errorf("After update callbacks values are not saved, %v", p.GetCallTimes()) } DB.Delete(&p) - if !reflect.DeepEqual(p.GetCallTimes(), []int64{1, 2, 1, 1, 0, 0, 1, 1, 2}) { + if !reflect.DeepEqual(p.GetCallTimes(), []int64{1, 2, 0, 1, 0, 0, 1, 1, 2}) { t.Errorf("After delete callbacks should be invoked successfully, %v", p.GetCallTimes()) }