Skip to content

Commit

Permalink
test(query): repro #5775
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Nov 5, 2017
1 parent d284104 commit a12d282
Showing 1 changed file with 37 additions and 7 deletions.
44 changes: 37 additions & 7 deletions test/model.discriminator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* Test dependencies.
*/

var start = require('./common'),
mongoose = start.mongoose,
Schema = mongoose.Schema,
assert = require('power-assert'),
util = require('util'),
clone = require('../lib/utils').clone,
random = require('../lib/utils').random;
var start = require('./common');
var mongoose = start.mongoose;
var Schema = mongoose.Schema;
var assert = require('power-assert');
var util = require('util');
var clone = require('../lib/utils').clone;
var random = require('../lib/utils').random;

/**
* Setup
Expand Down Expand Up @@ -591,6 +591,36 @@ describe('model', function() {
done();
});

it('nested discriminator key with projecting in parent (gh-5775)', function(done) {
var itemSchema = new Schema({
type: { type: String },
active: { type: Boolean, default: true }
}, { discriminatorKey: 'type' });

var collectionSchema = new Schema({
items: [itemSchema]
});

var s = new Schema({ count: Number });
collectionSchema.path('items').discriminator('type1', s);

var MyModel = db.model('Collection', collectionSchema);
var doc = {
items: [{ type: 'type1', active: false, count: 3 }]
};
MyModel.create(doc, function(error) {
assert.ifError(error);
MyModel.findOne({}).select('items').exec(function(error, doc) {
assert.ifError(error);
assert.equal(doc.items.length, 1);
assert.equal(doc.items[0].type, 'type1');
assert.strictEqual(doc.items[0].active, false);
assert.strictEqual(doc.items[0].count, 3);
done();
});
});
});

it('embedded discriminators with $push (gh-5009)', function(done) {
var eventSchema = new Schema({ message: String },
{ discriminatorKey: 'kind', _id: false });
Expand Down

0 comments on commit a12d282

Please sign in to comment.