* 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)
| 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. |
no outgoing calls
no test coverage detected