不要怂,就是干,撸起袖子干!

Commit e5d0cc43 by fogine Committed by Felix Becker

fixbug/ORDER clause was not included in subquery if `order` option value was pro…

…vided as plain string (not as an array value) (#6313)
1 parent 2ba12efb
# Future # Future
- [ADDED] include now supports string as an argument (on top of model/association), string will expand into an association matched literally from Model.associations - [ADDED] include now supports string as an argument (on top of model/association), string will expand into an association matched literally from Model.associations
- [FIXED] Accept dates as string while using `typeValidation` [#6453](https://github.com/sequelize/sequelize/issues/6453) - [FIXED] Accept dates as string while using `typeValidation` [#6453](https://github.com/sequelize/sequelize/issues/6453)
- [FIXED] - ORDER clause was not included in subquery if `order` option value was provided as plain string (not as an array value)
# 4.0.0-1 # 4.0.0-1
- [CHANGED] Removed `modelManager` parameter from `Model.init()` [#6437](https://github.com/sequelize/sequelize/issues/6437) - [CHANGED] Removed `modelManager` parameter from `Model.init()` [#6437](https://github.com/sequelize/sequelize/issues/6437)
......
...@@ -1541,7 +1541,11 @@ const QueryGenerator = { ...@@ -1541,7 +1541,11 @@ const QueryGenerator = {
mainQueryOrder.push(this.quote(t, model)); mainQueryOrder.push(this.quote(t, model));
} }
} else { } else {
mainQueryOrder.push(this.quote(typeof options.order === 'string' ? new Utils.Literal(options.order) : options.order, model)); var sql = this.quote(typeof options.order === 'string' ? new Utils.Literal(options.order) : options.order, model);
if (subQuery) {
subQueryOrder.push(sql);
}
mainQueryOrder.push(sql);
} }
return {mainQueryOrder, subQueryOrder}; return {mainQueryOrder, subQueryOrder};
......
...@@ -158,6 +158,28 @@ suite(Support.getTestDialectTeaser('SQL'), function() { ...@@ -158,6 +158,28 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
+') AS [user] LEFT OUTER JOIN [post] AS [POSTS] ON [user].[id] = [POSTS].[user_id];' +') AS [user] LEFT OUTER JOIN [post] AS [POSTS] ON [user].[id] = [POSTS].[user_id];'
}); });
testsql({
table: User.getTableName(),
model: User,
include: include,
attributes: [
['id_user', 'id'],
'email',
['first_name', 'firstName'],
['last_name', 'lastName']
],
order: '[user].[last_name] ASC'.replace(/\[/g, Support.sequelize.dialect.TICK_CHAR_LEFT).replace(/\]/g, Support.sequelize.dialect.TICK_CHAR_RIGHT),
limit: 30,
offset: 10,
hasMultiAssociation: true,//must be set only for mssql dialect here
subQuery: true
}, {
default: 'SELECT [user].*, [POSTS].[id] AS [POSTS.id], [POSTS].[title] AS [POSTS.title] FROM (' +
'SELECT [user].[id_user] AS [id], [user].[email], [user].[first_name] AS [firstName], [user].[last_name] AS [lastName] FROM [users] AS [user] ORDER BY [user].[last_name] ASC' +
sql.addLimitAndOffset({ limit: 30, offset:10, order: '`user`.`last_name` ASC' }) +
') AS [user] LEFT OUTER JOIN [post] AS [POSTS] ON [user].[id_user] = [POSTS].[user_id] ORDER BY [user].[last_name] ASC;'
});
var nestedInclude = Model._validateIncludedElements({ var nestedInclude = Model._validateIncludedElements({
include: [{ include: [{
attributes: ['title'], attributes: ['title'],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!