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

[MSSQL] Eliminate duplicate ORDER BY statements in select queries

Fixes #3489 and closes #3490.
1 parent c1bb8aef
......@@ -570,7 +570,14 @@ module.exports = (function() {
if (options.limit || options.offset) {
if (!options.order || (options.include && !subQueryOrder.length)) {
fragment += ' ORDER BY ' + this.quoteIdentifier(model.primaryKeyAttribute);
if(!isSubQuery && options.order) {
fragment += ', ';
}
else {
fragment += ' ORDER BY ';
}
fragment += this.quoteIdentifier(model.primaryKeyAttribute);
}
if (options.offset || options.limit) {
......
......@@ -562,6 +562,19 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(tasks[0].Worker.name).to.equal('worker');
});
});
it('returns the associated worker via task.worker, using limit and sort', function() {
return this.Task.findAll({
where: { title: 'homework' },
include: [this.Worker],
limit: 1,
order: 'title DESC'
}).then(function(tasks) {
expect(tasks).to.exist;
expect(tasks[0].Worker).to.exist;
expect(tasks[0].Worker.name).to.equal('worker');
});
});
});
describe('hasOne', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!