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 204c7e70
authored
Feb 19, 2014
by
Mick Hansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
quickfix for where to place order by when using subqueries
1 parent
28a35c30
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
4 deletions
lib/dialects/abstract/query-generator.js
lib/sequelize.js
test/dao-factory/findAll.test.js
lib/dialects/abstract/query-generator.js
View file @
204c7e7
...
@@ -767,12 +767,26 @@ module.exports = (function() {
...
@@ -767,12 +767,26 @@ module.exports = (function() {
// Add ORDER to sub or main query
// Add ORDER to sub or main query
if
(
options
.
order
)
{
if
(
options
.
order
)
{
options
.
order
=
Array
.
isArray
(
options
.
order
)
?
options
.
order
.
map
(
function
(
t
)
{
return
this
.
quote
(
t
,
factory
)
}.
bind
(
this
)).
join
(
', '
)
:
options
.
order
var
mainQueryOrder
=
[];
var
subQueryOrder
=
[];
if
(
subQuery
)
{
if
(
Array
.
isArray
(
options
.
order
))
{
subQueryItems
.
push
(
" ORDER BY "
+
options
.
order
)
options
.
order
.
forEach
(
function
(
t
)
{
if
(
subQuery
&&
!
(
t
[
0
]
instanceof
daoFactory
))
{
subQueryOrder
.
push
(
this
.
quote
(
t
,
factory
))
}
else
{
mainQueryOrder
.
push
(
this
.
quote
(
t
,
factory
))
}
}.
bind
(
this
))
}
else
{
}
else
{
mainQueryItems
.
push
(
" ORDER BY "
+
options
.
order
)
mainQueryOrder
.
push
(
options
.
order
)
}
if
(
mainQueryOrder
.
length
)
{
mainQueryItems
.
push
(
" ORDER BY "
+
mainQueryOrder
.
join
(
', '
))
}
if
(
subQueryOrder
.
length
)
{
subQueryItems
.
push
(
" ORDER BY "
+
subQueryOrder
.
join
(
', '
))
}
}
}
}
...
@@ -793,6 +807,7 @@ module.exports = (function() {
...
@@ -793,6 +807,7 @@ module.exports = (function() {
query
+=
subQueryItems
.
join
(
''
)
query
+=
subQueryItems
.
join
(
''
)
query
+=
") AS "
+
options
.
table
query
+=
") AS "
+
options
.
table
query
+=
mainJoinQueries
.
join
(
''
)
query
+=
mainJoinQueries
.
join
(
''
)
query
+=
mainQueryItems
.
join
(
''
)
}
else
{
}
else
{
query
=
mainQueryItems
.
join
(
''
)
query
=
mainQueryItems
.
join
(
''
)
}
}
...
...
lib/sequelize.js
View file @
204c7e7
...
@@ -139,6 +139,8 @@ module.exports = (function() {
...
@@ -139,6 +139,8 @@ module.exports = (function() {
Sequelize
.
DAOValidator
=
DAOValidator
Sequelize
.
DAOValidator
=
DAOValidator
Sequelize
.
DAOFactory
=
Sequelize
.
Model
=
DAOFactory
for
(
var
dataType
in
DataTypes
)
{
for
(
var
dataType
in
DataTypes
)
{
Sequelize
[
dataType
]
=
DataTypes
[
dataType
]
Sequelize
[
dataType
]
=
DataTypes
[
dataType
]
}
}
...
...
test/dao-factory/findAll.test.js
View file @
204c7e7
...
@@ -1029,6 +1029,28 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
...
@@ -1029,6 +1029,28 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
},
function
()
{
done
()})
},
function
()
{
done
()})
})
})
it
(
'sorts by 1st degree association while using limit'
,
function
(
done
)
{
var
self
=
this
async
.
forEach
([
[
'ASC'
,
'England'
,
'Energy'
],
[
'DESC'
,
'Korea'
,
'Tech'
]
],
function
(
params
,
callback
)
{
self
.
Country
.
findAll
({
include
:
[
self
.
Industry
],
order
:
[
[
self
.
Industry
,
'name'
,
params
[
0
]
]
],
limit
:
3
}).
done
(
function
(
err
,
countries
)
{
expect
(
err
).
not
.
to
.
be
.
ok
expect
(
countries
).
to
.
exist
expect
(
countries
[
0
]).
to
.
exist
expect
(
countries
[
0
].
name
).
to
.
equal
(
params
[
1
])
expect
(
countries
[
0
].
industries
).
to
.
exist
expect
(
countries
[
0
].
industries
[
0
]).
to
.
exist
expect
(
countries
[
0
].
industries
[
0
].
name
).
to
.
equal
(
params
[
2
])
callback
()
})
},
function
()
{
done
()})
})
it
(
'sorts by through table attribute'
,
function
(
done
)
{
it
(
'sorts by through table attribute'
,
function
(
done
)
{
var
self
=
this
var
self
=
this
async
.
forEach
([
[
'ASC'
,
'England'
,
'Energy'
],
[
'DESC'
,
'France'
,
'Media'
]
],
function
(
params
,
callback
)
{
async
.
forEach
([
[
'ASC'
,
'England'
,
'Energy'
],
[
'DESC'
,
'France'
,
'Media'
]
],
function
(
params
,
callback
)
{
...
...
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