Skip to content

Commit

Permalink
check the value of overwriteModels in options
Browse files Browse the repository at this point in the history
  • Loading branch information
Uditha Galappaththi committed Jun 3, 2024
1 parent 237e71a commit 1314b07
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 1314b07

Please sign in to comment.