Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check the value of overwriteModels in options #14646

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
check the value of overwriteModels in options
  • Loading branch information
Uditha Galappaththi committed Jun 3, 2024
commit 1314b074f2274ec6e2ed6f1550d235e2d6d69bb4
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