Skip to content

Commit

Permalink
test(discriminator): repro #7586
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Mar 22, 2019
1 parent 488ee06 commit 494945e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/model.discriminator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1284,5 +1284,18 @@ describe('model', function() {
assert.equal(clickEventUser1.collection.name, 'user1_events');
assert.equal(clickEventUser2.collection.name, 'user2_events');
});

it('uses correct discriminator when using `new BaseModel` (gh-7586)', function() {
const options = { discriminatorKey: 'kind' };

const BaseModel = mongoose.model('gh7586_Base',
Schema({ name: String }, options));
const ChildModel = BaseModel.discriminator('gh7586_Child',
Schema({ test: String }, options));

const doc = new BaseModel({ kind: 'gh7586_Child', name: 'a', test: 'b' });
assert.ok(doc instanceof ChildModel);
assert.equal(doc.test, 'b');
});
});
});

0 comments on commit 494945e

Please sign in to comment.