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 34b964bb
authored
Feb 21, 2016
by
Mick Hansen
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5458 from brendonboshell/master
empty array in where should return no data
2 parents
d3c25368
8c6c7740
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
lib/dialects/abstract/query-generator.js
test/unit/sql/where.test.js
lib/dialects/abstract/query-generator.js
View file @
34b964b
...
...
@@ -2004,9 +2004,20 @@ var QueryGenerator = {
return
item
&&
item
.
length
;
});
// $or: [] should return no data.
// $not of no restriction should also return no data
if
((
key
===
'$or'
||
key
===
'$not'
)
&&
value
.
length
===
0
)
{
return
'0 = 1'
;
}
return
value
.
length
?
outerBinding
+
'('
+
value
.
join
(
binding
)
+
')'
:
undefined
;
}
else
{
value
=
self
.
whereItemsQuery
(
value
,
options
,
binding
);
if
((
key
===
'$or'
||
key
===
'$not'
)
&&
!
value
)
{
return
'0 = 1'
;
}
return
value
?
outerBinding
+
'('
+
value
+
')'
:
undefined
;
}
}
...
...
test/unit/sql/where.test.js
View file @
34b964b
...
...
@@ -248,6 +248,20 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
mssql
:
"([group_id] = 1 OR ([user_id] = 2 AND [role] = N'admin'))"
});
});
testsql
(
'$or'
,
[],
{
default
:
"0 = 1"
});
testsql
(
'$or'
,
{},
{
default
:
"0 = 1"
});
test
(
"sequelize.or()"
,
function
()
{
expectsql
(
sql
.
whereItemQuery
(
undefined
,
this
.
sequelize
.
or
()),
{
default
:
"0 = 1"
});
});
});
suite
(
'$and'
,
function
()
{
...
...
@@ -313,6 +327,14 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
},
{
default
:
'NOT ([shared] = 1 AND ([group_id] = 1 OR [user_id] = 2))'
});
testsql
(
'$not'
,
[],
{
default
:
"0 = 1"
});
testsql
(
'$not'
,
{},
{
default
:
"0 = 1"
});
});
});
...
...
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