Skip to content

Commit b50319d

Browse files
committed
Fix after rebase
1 parent d054a74 commit b50319d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/sequence.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ Sequence.prototype._createCounterModel = function() {
180180
* @method _setHooks
181181
*/
182182
Sequence.prototype._setHooks = function() {
183+
var _this = this;
183184

184185
this._schema.pre('save', true, (function(sequence){
185186
return function(next, done) {
@@ -208,7 +209,7 @@ Sequence.prototype._setHooks = function() {
208209
if (obj) return next();
209210
else {
210211
referenceValue = _this._getCounterReferenceField(_thisquery._update);
211-
_this._setNextCounter(_this._options.reference_fields, referenceValue, function(err, seq) {
212+
_this._setNextCounterByReference(_this._options.reference_fields, referenceValue, function(err, seq) {
212213
if (err) return next();
213214
_thisquery._update['$setOnInsert'] = _thisquery._update['$setOnInsert'] || {};
214215
_thisquery._update['$setOnInsert'][_this._options.inc_field] = seq;
@@ -232,7 +233,7 @@ Sequence.prototype._setHooks = function() {
232233
if (obj) return next();
233234
else {
234235
referenceValue = _this._getCounterReferenceField(_thisquery._update);
235-
_this._setNextCounter(_this._options.reference_fields, referenceValue, function(err, seq) {
236+
_this._setNextCounterByReference(_this._options.reference_fields, referenceValue, function(err, seq) {
236237
if (err) return next();
237238
_thisquery._update['$setOnInsert'] = _thisquery._update['$setOnInsert'] || {};
238239
_thisquery._update['$setOnInsert'][_this._options.inc_field] = seq;
@@ -283,6 +284,10 @@ Sequence.prototype._setMethods = function() {
283284
Sequence.prototype._setNextCounter = function(doc, callback) {
284285
var id = this.getId();
285286
var referenceValue = this._getCounterReferenceField(doc);
287+
this._setNextCounterByReference(id, referenceValue, callback);
288+
};
289+
290+
Sequence.prototype._setNextCounterByReference = function(id, referenceValue, callback) {
286291
this._counterModel.findOneAndUpdate(
287292
{ id: id, reference_value: referenceValue },
288293
{ $inc: { seq: 1 } },

test/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ describe('Basic => ', function() {
237237
});
238238
var wrapper = function(schema, options) {
239239
var instance = AutoIncrement(schema, options);
240-
this.setNextCounterSpy = sinon.spy(instance, '_setNextCounter');
240+
this.setNextCounterSpy = sinon.spy(instance, '_setNextCounterByReference');
241241
return instance;
242242
}.bind(this);
243243
SimpleFieldSchema.plugin(wrapper, {id: 'id_hook_test', inc_field: 'id'});

0 commit comments

Comments
 (0)