Skip to content

model controller update function uses lodash merge instead of extend #2049

Closed
@ctchisholm

Description

@ctchisholm

When generating an endpoint API, the update function uses lodash merge instead of lodash extend. This results in no update happening if the object you are saving has arrays, some of whose elements were removed.

consider an object:

{ _id:'133453464567456', title:'test title', authors: [{name:'author1'},{name:'author2'}]}

now lets say we remove an author:
{ _id:'133453464567456', title:'test title', authors: [{name:'author1'}]}

If I use the current update function, the saved object still has both authors, because merge added it back in. Extend, on the other hand, will properly copy the entire new authors array to the model object for saving.

function saveUpdates(updates) {
return function(entity) {
var updated = _.merge(entity, updates);
return updated.save()
.then(updated => {
return updated;
});
};
}

should be replaced with

function saveUpdates(updates) {
return function(entity) {
var updated = _.extend(entity, updates);
return updated.save()
.then(updated => {
return updated;
});
};
}

  • I understand that GitHub issues are not for tech support, but for questions specific to this generator, bug reports, and feature requests.
Item Version
generator-angular-fullstack x.x.x
Node x.x.x
npm x.x.x
Operating System OS X 10 / Windows 10 / Ubuntu 15.10 / etc
etc etc
Item Answer
Transpiler Babel / TypeScript
Markup HTML / Jade
CSS CSS / LESS / SCSS / Stylus
Router ngRoute / ui-router
Build Tool Grunt / Gulp
Client Tests Jasmine / Mocha
DB MongoDB / SQL
Auth Y / N
etc etc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions