Skip to content

Commit 060fcdf

Browse files
committed
fix(model): increment version when $set-ing it in a save() that requires a version bump
Fix #5779
1 parent ab668da commit 060fcdf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/model.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,13 @@ Model.prototype.$__version = function(where, delta) {
652652
}
653653

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

0 commit comments

Comments
 (0)