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.)
This commit is contained in:
James Hogge 2019-08-31 13:28:56 +01:00
parent 836fb2c19d
commit 907f875972

View File

@ -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()))
}