Don't save ignored fields into database

This commit is contained in:
Jinzhu 2018-09-10 06:03:41 +08:00
parent 6f58f8a52c
commit dc3b2476c4
2 changed files with 2 additions and 2 deletions

View File

@ -59,7 +59,7 @@ func createCallback(scope *Scope) {
for _, field := range scope.Fields() { for _, field := range scope.Fields() {
if scope.changeableField(field) { if scope.changeableField(field) {
if field.IsNormal { if field.IsNormal && !field.IsIgnored {
if field.IsBlank && field.HasDefaultValue { if field.IsBlank && field.HasDefaultValue {
blankColumnsWithDefaultValue = append(blankColumnsWithDefaultValue, scope.Quote(field.DBName)) blankColumnsWithDefaultValue = append(blankColumnsWithDefaultValue, scope.Quote(field.DBName))
scope.InstanceSet("gorm:blank_columns_with_default_value", blankColumnsWithDefaultValue) scope.InstanceSet("gorm:blank_columns_with_default_value", blankColumnsWithDefaultValue)

View File

@ -907,7 +907,7 @@ func (scope *Scope) updatedAttrsWithValues(value interface{}) (results map[strin
results[field.DBName] = value results[field.DBName] = value
} else { } else {
err := field.Set(value) err := field.Set(value)
if field.IsNormal { if field.IsNormal && !field.IsIgnored {
hasUpdate = true hasUpdate = true
if err == ErrUnaddressable { if err == ErrUnaddressable {
results[field.DBName] = value results[field.DBName] = value