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

Commit bb1b4127 by fogine Committed by Sushant

Bugfix/order clause in subquery - for the `v3` (#6268)

* fixbug/ORDER clause was not included in subquery if `order` option value was provided as plain string (not as an array value)

* fixbug/select query unit test - use dialect specific sql column signs

* fix test case bug for mssql dialect

* indentation
1 parent f75d4865
# Future
- [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)
# 3.24.1
- [FIXED] Add `parent`, `original` and `sql` properties to `UniqueConstraintError`
......@@ -8,6 +9,8 @@
- [ADDED] `restartIdentity` option for truncate in postgres [#5356](https://github.com/sequelize/sequelize/issues/5356)
# 3.23.5
# 3.23.4
- [FIXED] Fixed an issue where custom-named model fields break when offsetting, ordering, and including hasMany simultaneously. [#5985](https://github.com/sequelize/sequelize/issues/5985)
- [FIXED] Don't remove includes from count queries and unify findAndCount and count queries. [#6123](https://github.com/sequelize/sequelize/issues/6123)
- [FIXED] `Model.count` don't include attributes [#5057](https://github.com/sequelize/sequelize/issues/5057)
......
......@@ -1667,7 +1667,11 @@ var QueryGenerator = {
mainQueryOrder.push(this.quote(t, model));
}.bind(this));
} 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 {
......
......@@ -234,6 +234,28 @@ suite(Support.getTestDialectTeaser('SQL'), function() {
+') 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({
include: [{
attributes: ['title'],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!