From 907f875972dc46e3129f135f6bbc0d6c8f9152b5 Mon Sep 17 00:00:00 2001 From: James Hogge Date: Sat, 31 Aug 2019 13:28:56 +0100 Subject: [PATCH] Fixed Ignore Blank Fields On Create Removed erroneous IsPrimaryKey check which caused fields that were not part of the Primary Key but were Blank to be inserted. (Particularly a problem because DeletedAt would be set to the zero value.) --- callback_create.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/callback_create.go b/callback_create.go index 87aba8ee..a607c0d6 100644 --- a/callback_create.go +++ b/callback_create.go @@ -63,7 +63,7 @@ func createCallback(scope *Scope) { if field.IsBlank && field.HasDefaultValue { blankColumnsWithDefaultValue = append(blankColumnsWithDefaultValue, scope.Quote(field.DBName)) scope.InstanceSet("gorm:blank_columns_with_default_value", blankColumnsWithDefaultValue) - } else if !field.IsPrimaryKey || !field.IsBlank { + } else if !field.IsBlank { columns = append(columns, scope.Quote(field.DBName)) placeholders = append(placeholders, scope.AddToVars(field.Field.Interface())) }