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 6347f7d5
authored
Jul 31, 2018
by
u9r52sld
Committed by
Sushant
Jul 30, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(scope): incorrect query generated when sequelize.fn used with scopes(#9730)
1 parent
d5e9f124
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
3 deletions
lib/model.js
test/integration/model/scope.test.js
test/unit/model/scope.test.js
lib/model.js
View file @
6347f7d
...
...
@@ -1532,7 +1532,14 @@ class Model {
if
(
scope
)
{
_
.
assignWith
(
self
.
_scope
,
scope
,
(
objectValue
,
sourceValue
,
key
)
=>
{
if
(
key
===
'where'
)
{
return
Array
.
isArray
(
sourceValue
)
?
sourceValue
:
Object
.
assign
(
objectValue
||
{},
sourceValue
);
if
(
Array
.
isArray
(
sourceValue
))
{
return
sourceValue
;
}
else
{
if
(
sourceValue
instanceof
Utils
.
SequelizeMethod
)
{
sourceValue
=
{
[
Op
.
and
]:
sourceValue
};
}
return
Object
.
assign
(
objectValue
||
{},
sourceValue
);
}
}
else
if
([
'attributes'
,
'include'
,
'group'
].
indexOf
(
key
)
>=
0
&&
Array
.
isArray
(
objectValue
)
&&
Array
.
isArray
(
sourceValue
))
{
return
objectValue
.
concat
(
sourceValue
);
}
...
...
test/integration/model/scope.test.js
View file @
6347f7d
...
...
@@ -50,6 +50,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
},
access_level
:
5
}
},
like_t
:
{
where
:
Sequelize
.
where
(
Sequelize
.
fn
(
'LOWER'
,
Sequelize
.
col
(
'username'
)),
'LIKE'
,
'%t%'
)
}
}
});
...
...
@@ -108,5 +111,12 @@ describe(Support.getTestDialectTeaser('Model'), () => {
return
this
.
ScopeMe
.
scope
(
'issue8473'
).
findAll
();
});
});
it
(
'should not throw error with sequelize.where'
,
function
()
{
return
this
.
ScopeMe
.
scope
(
'like_t'
).
findAll
()
.
then
(
records
=>
{
expect
(
records
).
to
.
have
.
length
(
2
);
});
});
});
});
test/unit/model/scope.test.js
View file @
6347f7d
...
...
@@ -2,6 +2,8 @@
const
chai
=
require
(
'chai'
),
expect
=
chai
.
expect
,
Sequelize
=
require
(
__dirname
+
'/../../../index'
),
Op
=
Sequelize
.
Op
,
Support
=
require
(
__dirname
+
'/../support'
),
DataTypes
=
require
(
__dirname
+
'/../../../lib/data-types'
),
current
=
Support
.
sequelize
;
...
...
@@ -28,6 +30,9 @@ describe(Support.getTestDialectTeaser('Model'), () => {
something
:
false
}
},
sequelize_where
:
{
where
:
Sequelize
.
where
()
},
users
:
{
include
:
[
{
model
:
User
}
...
...
@@ -135,10 +140,11 @@ describe(Support.getTestDialectTeaser('Model'), () => {
});
it
(
'should be able to merge scopes'
,
()
=>
{
expect
(
Company
.
scope
(
'somethingTrue'
,
'somethingFalse'
).
_scope
).
to
.
deep
.
equal
({
expect
(
Company
.
scope
(
'somethingTrue'
,
'somethingFalse'
,
'sequelize_where'
).
_scope
).
to
.
deep
.
equal
({
where
:
{
something
:
false
,
somethingElse
:
42
somethingElse
:
42
,
[
Op
.
and
]:
Sequelize
.
where
()
},
limit
:
5
});
...
...
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