Skip to content

Commit

Permalink
Fix updates, albeit not optimally.
Browse files Browse the repository at this point in the history
  • Loading branch information
martindale committed Mar 18, 2015
1 parent 63bcfd1 commit b4eeaa6
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/Resource/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,19 @@ Resource.prototype.update = function( query , params , complete ) {
if (!complete) var complete = new Function();
if (!query) return complete('no query');

Model.findOneAndUpdate( query ).exec(function(err, doc) {
Model.findOne( query ).exec(function(err, doc) {
if (err) return complete( err );
if (!doc) return complete( 404 );

Object.keys( params ).forEach(function(p) {
doc[ p ] = params[ p ];
});

// TODO: consider offering a changeset.
self.emit('update', doc );
complete( err , doc );

doc.save(function() {
// TODO: consider offering a changeset.
self.emit('update', doc );
complete( err , doc );
});
});
}

Expand Down

0 comments on commit b4eeaa6

Please sign in to comment.