diff --git a/models/utils/common.go b/models/utils/common.go index 1e227ab..a31a6f6 100755 --- a/models/utils/common.go +++ b/models/utils/common.go @@ -120,13 +120,23 @@ func ModelGenericUpdateOne(change map[string]interface{}, id string, a Accessor) for k, v := range change { // apply the changes, with a flatten method loaded[k] = v } - return r, loaded, 200, nil + newObj := a.NewObj() + b, err = json.Marshal(loaded) + if err != nil { + return nil, loaded, 400, nil + } + err = json.Unmarshal(b, newObj) + if err != nil { + return nil, loaded, 400, nil + } + return newObj, loaded, 200, nil } // GenericLoadOne loads one object from the database (generic) // json expected in entry is a flatted object no need to respect the inheritance hierarchy func GenericUpdateOne(change map[string]interface{}, id string, a Accessor) (DBObject, int, error) { obj, loaded, c, err := ModelGenericUpdateOne(change, id, a) + if err != nil { return nil, c, err }