不要怂,就是干,撸起袖子干!

Commit 438baac0 by Oscar Reyes Committed by Sushant

feat: added _scopeName property in instance (#8753)

1 parent 73db603d
Showing with 16 additions and 0 deletions
......@@ -842,6 +842,7 @@ class Model {
this._findAutoIncrementAttribute();
this._scope = this.options.defaultScope;
this._scopeNames = ['defaultScope'];
if (_.isPlainObject(this._scope)) {
this._conformOptions(this._scope, this);
......@@ -1327,6 +1328,7 @@ class Model {
Object.defineProperty(self, 'name', {value: this.name});
self._scope = {};
self._scopeNames = [];
self.scoped = true;
if (!option) {
......@@ -1375,6 +1377,8 @@ class Model {
return objectValue ? objectValue : sourceValue;
});
self._scopeNames.push(scopeName ? scopeName : 'defaultScope');
} else {
throw new sequelizeErrors.SequelizeScopeError('Invalid scope ' + scopeName + ' called.');
}
......
......@@ -181,6 +181,18 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
});
it('should be able to check default scope name', () => {
expect(Company._scopeNames).to.include('defaultScope');
});
it('should be able to check custom scope name', () => {
expect(Company.scope('users')._scopeNames).to.include('users');
});
it('should be able to check multiple custom scope names', () => {
expect(Company.scope('users', 'projects')._scopeNames).to.include.members(['users', 'projects']);
});
it('should be able to merge two scoped includes', () => {
expect(Company.scope('users', 'projects')._scope).to.deep.equal({
include: [
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!