Skip to content

Commit

Permalink
fix(model): modify discriminator() class in place
Browse files Browse the repository at this point in the history
Fix #5175
  • Loading branch information
vkarpov15 committed Apr 22, 2017
1 parent 1237132 commit a2addca
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/model.js
Expand Up @@ -829,8 +829,10 @@ Model.prototype.model = function model(name) {
*/

Model.discriminator = function(name, schema) {
var model;
if (typeof name === 'function') {
name = utils.getFunctionName(name);
model = name;
name = utils.getFunctionName(model);
}

schema = discriminator(this, name, schema);
Expand All @@ -840,7 +842,10 @@ Model.discriminator = function(name, schema) {

schema.$isRootDiscriminator = true;

this.discriminators[name] = this.db.model(name, schema, this.collection.name);
if (!model) {
model = this.db.model(name, schema, this.collection.name);
}
this.discriminators[name] = model;
var d = this.discriminators[name];
d.prototype.__proto__ = this.prototype;
Object.defineProperty(d, 'baseModelName', {
Expand Down

0 comments on commit a2addca

Please sign in to comment.