Skip to content

Commit

Permalink
fix empty values when casting other changeset (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fs02 authored Mar 5, 2019
1 parent c1f7394 commit f36c5cf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
5 changes: 2 additions & 3 deletions changeset/cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func Cast(data interface{}, params params.Params, fields []string, opts ...Optio
options.apply(opts)

var ch *Changeset
var zero bool
if existingCh, ok := data.(Changeset); ok {
ch = &existingCh
} else if existingCh, ok := data.(*Changeset); ok {
Expand All @@ -30,7 +29,7 @@ func Cast(data interface{}, params params.Params, fields []string, opts ...Optio
ch = &Changeset{}
ch.params = params
ch.changes = make(map[string]interface{})
ch.values, ch.types, zero = mapSchema(data)
ch.values, ch.types, ch.zero = mapSchema(data)
}

for _, field := range fields {
Expand All @@ -48,7 +47,7 @@ func Cast(data interface{}, params params.Params, fields []string, opts ...Optio
if change, valid := params.GetWithType(field, typ); valid {
value, vexist := ch.values[field]

if (typ.Kind() == reflect.Slice || typ.Kind() == reflect.Array) || (zero && change != nil) || (!vexist && change != nil) || (vexist && value != change) {
if (typ.Kind() == reflect.Slice || typ.Kind() == reflect.Array) || (ch.zero && change != nil) || (!vexist && change != nil) || (vexist && value != change) {
ch.changes[field] = change
}
} else {
Expand Down
1 change: 1 addition & 0 deletions changeset/changeset.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Changeset struct {
values map[string]interface{}
types map[string]reflect.Type
constraints Constraints
zero bool
}

// Errors of changeset.
Expand Down

0 comments on commit f36c5cf

Please sign in to comment.