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

Commit c0522cf2 by Matt Broadstone

Merge pull request #3784 from pmhpereira/master

[MSSQL] Eliminate duplicate ORDER BY statements in select queries
2 parents 549037a7 ec6bec87
...@@ -576,7 +576,8 @@ module.exports = (function() { ...@@ -576,7 +576,8 @@ module.exports = (function() {
if (options.limit || options.offset) { if (options.limit || options.offset) {
if (!options.order || (options.include && !subQueryOrder.length)) { if (!options.order || (options.include && !subQueryOrder.length)) {
fragment += ' ORDER BY ' + this.quoteIdentifier(model.primaryKeyAttribute); fragment += (options.order && !isSubQuery) ? ', ' : ' ORDER BY ';
fragment += this.quoteIdentifier(model.primaryKeyAttribute);
} }
if (options.offset || options.limit) { if (options.offset || options.limit) {
......
...@@ -562,6 +562,19 @@ describe(Support.getTestDialectTeaser('Model'), function() { ...@@ -562,6 +562,19 @@ describe(Support.getTestDialectTeaser('Model'), function() {
expect(tasks[0].Worker.name).to.equal('worker'); 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() { describe('hasOne', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!