MCPcopy
hub / github.com/sequelize/sequelize / addScope

Method addScope

lib/model.js:1472–1484  ·  view source on GitHub ↗

* Add a new scope to the model. This is especially useful for adding scopes with includes, when the model you want to include is not available at the time this model is defined. * * By default this will throw an error if a scope with that name already exists. Pass `override: true` in the optio

(name, scope, options)

Source from the content-addressed store, hash-verified

1470 * @param {boolean} [options.override=false] override old scope if already defined
1471 */
1472 static addScope(name, scope, options) {
1473 options = { override: false, ...options };
1474
1475 if ((name === 'defaultScope' && Object.keys(this.options.defaultScope).length > 0 || name in this.options.scopes) && options.override === false) {
1476 throw new Error(`The scope ${name} already exists. Pass { override: true } as options to silence this error`);
1477 }
1478
1479 if (name === 'defaultScope') {
1480 this.options.defaultScope = this._scope = scope;
1481 } else {
1482 this.options.scopes[name] = scope;
1483 }
1484 }
1485
1486 /**
1487 * Apply a scope created in `define` to the model.

Callers 6

User.tsFile · 0.80
scope.test.jsFile · 0.80
increment.test.jsFile · 0.80
merge.test.jsFile · 0.80
scope.test.jsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected