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 c1bb8aef
authored
May 17, 2015
by
Jan Aagaard Meier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix scopes to support aliassed models. Closes #3690
1 parent
c4b5f2af
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
lib/model.js
test/unit/model/scope.test.js
lib/model.js
View file @
c1bb8ae
...
@@ -1805,7 +1805,14 @@ module.exports = (function() {
...
@@ -1805,7 +1805,14 @@ module.exports = (function() {
// Reverse so we consider the latest include first.
// Reverse so we consider the latest include first.
// This is used if several scopes specify the same include - the last scope should take precendence
// This is used if several scopes specify the same include - the last scope should take precendence
scope
.
include
.
reverse
().
forEach
(
function
(
scopeInclude
)
{
scope
.
include
.
reverse
().
forEach
(
function
(
scopeInclude
)
{
if
(
!
_
.
any
(
options
.
include
,
_
.
matchesDots
(
'model.name'
,
scopeInclude
.
model
.
name
)))
{
if
(
!
_
.
any
(
options
.
include
,
function
matchesModelAndAlias
(
item
)
{
var
sameModel
=
item
.
model
.
name
===
scopeInclude
.
model
.
name
;
if
(
sameModel
&&
item
.
as
)
{
return
item
.
as
===
scopeInclude
.
as
;
}
return
sameModel
;
}))
{
options
.
include
.
push
(
scopeInclude
);
options
.
include
.
push
(
scopeInclude
);
}
}
});
});
...
@@ -1948,7 +1955,7 @@ module.exports = (function() {
...
@@ -1948,7 +1955,7 @@ module.exports = (function() {
model
=
include
.
target
;
model
=
include
.
target
;
}
}
include
=
{
model
:
model
,
association
:
include
};
include
=
{
model
:
model
,
association
:
include
,
as
:
include
.
as
};
}
else
if
(
include
instanceof
Model
)
{
}
else
if
(
include
instanceof
Model
)
{
model
=
include
;
model
=
include
;
...
@@ -1964,6 +1971,9 @@ module.exports = (function() {
...
@@ -1964,6 +1971,9 @@ module.exports = (function() {
if
(
!
include
.
model
)
{
if
(
!
include
.
model
)
{
include
.
model
=
model
;
include
.
model
=
model
;
}
}
if
(
!
include
.
as
)
{
include
.
as
=
include
.
association
.
as
;
}
}
else
{
}
else
{
model
=
include
.
model
;
model
=
include
.
model
;
}
}
...
...
test/unit/model/scope.test.js
View file @
c1bb8ae
...
@@ -196,6 +196,22 @@ describe(Support.getTestDialectTeaser('Model'), function() {
...
@@ -196,6 +196,22 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect
(
options
.
include
[
0
]).
to
.
deep
.
equal
({
model
:
Project
,
where
:
{
something
:
true
}});
expect
(
options
.
include
[
0
]).
to
.
deep
.
equal
({
model
:
Project
,
where
:
{
something
:
true
}});
});
});
it
(
'should be able to merge aliassed includes with the same model'
,
function
()
{
var
scope
=
{
include
:
[{
model
:
User
,
as
:
'someUser'
}]
};
var
options
=
{
include
:
[{
model
:
User
,
as
:
'otherUser'
}]
};
current
.
Model
.
$injectScope
(
scope
,
options
);
expect
(
options
.
include
).
to
.
have
.
length
(
2
);
expect
(
options
.
include
[
0
]).
to
.
deep
.
equal
({
model
:
User
,
as
:
'otherUser'
});
expect
(
options
.
include
[
1
]).
to
.
deep
.
equal
({
model
:
User
,
as
:
'someUser'
});
});
it
(
'should be able to merge scoped include with include in find'
,
function
()
{
it
(
'should be able to merge scoped include with include in find'
,
function
()
{
var
scope
=
{
var
scope
=
{
include
:
[
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