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

Method addScope

src/model.js:1523–1535  ·  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

1521 * @param {boolean} [options.override=false] override old scope if already defined
1522 */
1523 static addScope(name, scope, options) {
1524 options = { override: false, ...options };
1525
1526 if ((name === 'defaultScope' && Object.keys(this.options.defaultScope).length > 0 || name in this.options.scopes) && options.override === false) {
1527 throw new Error(`The scope ${name} already exists. Pass { override: true } as options to silence this error`);
1528 }
1529
1530 if (name === 'defaultScope') {
1531 this.options.defaultScope = this._scope = scope;
1532 } else {
1533 this.options.scopes[name] = scope;
1534 }
1535 }
1536
1537 /**
1538 * Apply a scope created in `define` to the model.

Callers 6

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

Calls

no outgoing calls

Tested by

no test coverage detected