Skip to content

Commit

Permalink
Skip to-many check in Equal if both lengths are zero
Browse files Browse the repository at this point in the history
reflect.DeepEqual returns false if a nil slice is compared to an
empty slice. For the purpose of the Equal function, both a nil and
an empty slice are considered equal which is not an opinion that
the reflect.DeepEqual function shares.
  • Loading branch information
mfcochauxlaberge committed Aug 21, 2019
1 parent 82d287e commit d1e6300
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions resource.go
Expand Up @@ -115,8 +115,12 @@ func Equal(r1, r2 Resource) bool {
return false
}
} else {
if !reflect.DeepEqual(r1.GetToMany(rel1.Name), r2.GetToMany(rel2.Name)) {
return false
v1 := r1.GetToMany(rel1.Name)
v2 := r2.GetToMany(rel2.Name)
if len(v1) != 0 || len(v2) != 0 {
if !reflect.DeepEqual(v1, v2) {
return false
}
}
}
}
Expand Down

0 comments on commit d1e6300

Please sign in to comment.