Skip to content

Commit

Permalink
fix(model): increment version when $set-ing it in a save() that requi…
Browse files Browse the repository at this point in the history
…res a version bump

Fix #5779
  • Loading branch information
vkarpov15 committed Nov 7, 2017
1 parent ab668da commit 060fcdf
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,13 @@ Model.prototype.$__version = function(where, delta) {
}

if (VERSION_INC === (VERSION_INC & this.$__.version)) {
if (!delta.$set || typeof delta.$set[key] === 'undefined') {
delta.$inc || (delta.$inc = {});
if (get(delta.$set, key, null) != null) {
// Version key is getting set, means we'll increment the doc's version
// after a successful save, so we should set the incremented version so
// future saves don't fail (gh-5779)
++delta.$set[key];
} else {
delta.$inc = delta.$inc || {};
delta.$inc[key] = 1;
}
}
Expand Down

0 comments on commit 060fcdf

Please sign in to comment.