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 e695b92c
authored
Oct 09, 2017
by
Gabe Gorelick
Committed by
Sushant
Oct 09, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(model): handle Symbol-only where clauses (#8435)
1 parent
2a3b3dba
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
3 deletions
lib/model.js
lib/query-interface.js
lib/utils.js
test/integration/model.test.js
lib/model.js
View file @
e695b92
...
...
@@ -83,7 +83,7 @@ class Model {
deletedAtObject
[
deletedAtAttribute
.
field
||
deletedAtCol
]
=
deletedAtDefaultValue
;
if
(
_
.
is
Empty
(
options
.
where
))
{
if
(
Utils
.
isWhere
Empty
(
options
.
where
))
{
options
.
where
=
deletedAtObject
;
}
else
{
options
.
where
=
{
[
Op
.
and
]:
[
deletedAtObject
,
options
.
where
]
};
...
...
lib/query-interface.js
View file @
e695b92
...
...
@@ -849,7 +849,7 @@ class QueryInterface {
options
=
_
.
clone
(
options
);
if
(
!
_
.
is
Empty
(
where
))
{
if
(
!
Utils
.
isWhere
Empty
(
where
))
{
wheres
.
push
(
where
);
}
...
...
lib/utils.js
View file @
e695b92
...
...
@@ -574,7 +574,7 @@ exports.mapIsolationLevelStringToTedious = (isolationLevel, tedious) => {
* @private
*/
function
getOperators
(
obj
)
{
return
_
.
intersection
(
Object
.
getOwnPropertySymbols
(
obj
),
operatorsArray
);
return
_
.
intersection
(
Object
.
getOwnPropertySymbols
(
obj
||
{}
),
operatorsArray
);
}
exports
.
getOperators
=
getOperators
;
...
...
@@ -599,3 +599,15 @@ function getComplexSize(obj) {
return
Array
.
isArray
(
obj
)
?
obj
.
length
:
getComplexKeys
(
obj
).
length
;
}
exports
.
getComplexSize
=
getComplexSize
;
/**
* Returns true if a where clause is empty, even with Symbols
*
* @param {Object} obj
* @return {Boolean}
* @private
*/
function
isWhereEmpty
(
obj
)
{
return
_
.
isEmpty
(
obj
)
&&
getOperators
(
obj
).
length
===
0
;
}
exports
.
isWhereEmpty
=
isWhereEmpty
;
test/integration/model.test.js
View file @
e695b92
...
...
@@ -708,6 +708,29 @@ describe(Support.getTestDialectTeaser('Model'), () => {
expect
(
u
.
username
).
to
.
equal
(
'A fancy name'
);
});
});
// https://github.com/sequelize/sequelize/issues/8406
it
(
'should work if model is paranoid and only operator in where clause is a Symbol'
,
function
()
{
const
User
=
this
.
sequelize
.
define
(
'User'
,
{
username
:
Sequelize
.
STRING
},
{
paranoid
:
true
}
);
return
User
.
sync
({
force
:
true
})
.
then
(()
=>
{
return
User
.
create
({
username
:
'foo'
});
})
.
then
(()
=>
{
return
User
.
findOne
({
where
:
{
[
Sequelize
.
Op
.
or
]:
[
{
username
:
'bar'
},
{
username
:
'baz'
}
]
}
});
})
.
then
(
user
=>
{
expect
(
user
).
to
.
not
.
be
.
ok
;
});
});
});
describe
(
'findOrInitialize'
,
()
=>
{
...
...
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