Skip to content

Commit f36c5cf

Browse files
authored
fix empty values when casting other changeset (#53)
1 parent c1f7394 commit f36c5cf

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

changeset/cast.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ func Cast(data interface{}, params params.Params, fields []string, opts ...Optio
2121
options.apply(opts)
2222

2323
var ch *Changeset
24-
var zero bool
2524
if existingCh, ok := data.(Changeset); ok {
2625
ch = &existingCh
2726
} else if existingCh, ok := data.(*Changeset); ok {
@@ -30,7 +29,7 @@ func Cast(data interface{}, params params.Params, fields []string, opts ...Optio
3029
ch = &Changeset{}
3130
ch.params = params
3231
ch.changes = make(map[string]interface{})
33-
ch.values, ch.types, zero = mapSchema(data)
32+
ch.values, ch.types, ch.zero = mapSchema(data)
3433
}
3534

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

51-
if (typ.Kind() == reflect.Slice || typ.Kind() == reflect.Array) || (zero && change != nil) || (!vexist && change != nil) || (vexist && value != change) {
50+
if (typ.Kind() == reflect.Slice || typ.Kind() == reflect.Array) || (ch.zero && change != nil) || (!vexist && change != nil) || (vexist && value != change) {
5251
ch.changes[field] = change
5352
}
5453
} else {

changeset/changeset.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Changeset struct {
1515
values map[string]interface{}
1616
types map[string]reflect.Type
1717
constraints Constraints
18+
zero bool
1819
}
1920

2021
// Errors of changeset.

0 commit comments

Comments
 (0)