From e2f0ab4aa13b8e3aa5805732b5fbbc760d6708ba Mon Sep 17 00:00:00 2001 From: Roy Reznik Date: Tue, 5 May 2020 23:25:31 +0300 Subject: [PATCH] Fix bug where association fields got updated even if fields were blank --- callback_update.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/callback_update.go b/callback_update.go index 699e534b..2931503e 100644 --- a/callback_update.go +++ b/callback_update.go @@ -76,7 +76,7 @@ func updateCallback(scope *Scope) { for _, field := range scope.Fields() { if scope.changeableField(field) { if !field.IsPrimaryKey && field.IsNormal && (field.Name != "CreatedAt" || !field.IsBlank) { - if !field.IsForeignKey || !field.IsBlank || !field.HasDefaultValue { + 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" {