Skip to content

Commit

Permalink
fix(populate): fix race condition that popped up when refactoring Pop…
Browse files Browse the repository at this point in the history
…ulateOptions

Re: #6520
Re: #5858
  • Loading branch information
vkarpov15 committed May 23, 2019
1 parent 13f8073 commit baf8cba
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -3882,7 +3882,7 @@ function _populate(model, docs, paths, cache, callback) {
let path;
while (i--) {
path = paths[i];
populate(model, docs, path, next);
populate(model, docs, Object.assign({}, path), next);
}

function next(err) {
Expand Down
3 changes: 2 additions & 1 deletion lib/options/PopulateOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class PopulateOptions {
if (obj == null) {
return;
}
Object.assign(this, utils.clone(obj));
obj = utils.clone(obj);
Object.assign(this, obj);
if (typeof obj.subPopulate === 'object') {
this.populate = obj.subPopulate;
}
Expand Down
4 changes: 2 additions & 2 deletions test/model.populate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6502,7 +6502,7 @@ describe('model: populate:', function() {
const dateActivitySchema = new Schema({
postedBy: {
type: Schema.Types.ObjectId,
ref: 'gh5858',
ref: 'gh5858_User',
required: true
}
}, options);
Expand All @@ -6519,7 +6519,7 @@ describe('model: populate:', function() {
kind: String
}, options);

const User = db.model('gh5858', { name: String });
const User = db.model('gh5858_User', { name: String });
const Activity = db.model('gh5858_0', activitySchema);
const DateActivity = Activity.discriminator('gh5858_1', dateActivitySchema);
const EventActivity = Activity.discriminator('gh5858_2', eventActivitySchema);
Expand Down

0 comments on commit baf8cba

Please sign in to comment.