Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
public
/
sequelize
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
不要怂,就是干,撸起袖子干!
Commit 438baac0
authored
Dec 06, 2017
by
Oscar Reyes
Committed by
Sushant
Dec 06, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: added _scopeName property in instance (#8753)
1 parent
73db603d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
0 deletions
lib/model.js
test/unit/model/scope.test.js
lib/model.js
View file @
438baac
...
...
@@ -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.'
);
}
...
...
test/unit/model/scope.test.js
View file @
438baac
...
...
@@ -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
:
[
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment