Skip to content

Commit

Permalink
Merge pull request #14646 from uditha-g/master
Browse files Browse the repository at this point in the history
check the value of overwriteModels in options
  • Loading branch information
vkarpov15 authored Jun 4, 2024
2 parents 563f293 + 1314b07 commit c71ba5e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ Model.discriminator = function(name, schema, options) {
const value = utils.isPOJO(options) ? options.value : options;
const clone = typeof options.clone === 'boolean' ? options.clone : true;
const mergePlugins = typeof options.mergePlugins === 'boolean' ? options.mergePlugins : true;
const overwriteModels = typeof options.overwriteModels === 'boolean' ? options.overwriteModels : false;

_checkContext(this, 'discriminator');

Expand All @@ -1245,8 +1246,8 @@ Model.discriminator = function(name, schema, options) {
schema = schema.clone();
}

schema = discriminator(this, name, schema, value, mergePlugins, options.mergeHooks);
if (this.db.models[name] && !schema.options.overwriteModels) {
schema = discriminator(this, name, schema, value, mergePlugins, options.mergeHooks, overwriteModels);
if (this.db.models[name] && !schema.options.overwriteModels && !overwriteModels) {
throw new OverwriteModelError(name);
}

Expand Down

0 comments on commit c71ba5e

Please sign in to comment.