Skip to content

Commit

Permalink
test(populate): repro #4104
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Apr 29, 2016
1 parent 44cfd47 commit 91c3eac
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/model.populate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3668,5 +3668,44 @@ describe('model: populate:', function() {
done
);
});

it('dynref bug (gh-4104)', function(done) {
var PersonSchema = new Schema({
name: { type: String }
});

var AnimalSchema = new Schema({
name: { type: String }
});

var ThingSchema = new Schema({
createdByModel: { type: String },
createdBy: {
type: mongoose.Schema.Types.ObjectId, refPath: 'createdByModel'
}
});

var Thing = db.model('Thing4104', ThingSchema);
var Person = db.model('Person4104', PersonSchema);
var Animal = db.model('Animal4104', AnimalSchema);

Person.create({ name: 'Val' }, function(error, person) {
assert.ifError(error);
Animal.create({ name: 'Air Bud' }, function(error, animal) {
assert.ifError(error);
var obj1 = { createdByModel: 'Person4104', createdBy: person._id };
var obj2 = { createdByModel: 'Animal4104', createdBy: animal._id };
Thing.create(obj1, obj2, function(error) {
assert.ifError(error);
Thing.find({}).populate('createdBy').exec(function(error, things) {
assert.ifError(error);
assert.ok(things[0].createdBy.name);
assert.ok(things[1].createdBy.name);
done();
});
});
});
});
});
});
});

0 comments on commit 91c3eac

Please sign in to comment.