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

Commit a4156ebc by Mick Hansen

order by subquery logic should also work in cases of {model: Model} instead of just Model

1 parent e2b5dc7d
......@@ -780,7 +780,7 @@ module.exports = (function() {
if (Array.isArray(options.order)) {
options.order.forEach(function (t) {
if (subQuery && !(t[0] instanceof daoFactory)) {
if (subQuery && !(t[0] instanceof daoFactory) && !(t[0].model instanceof daoFactory)) {
subQueryOrder.push(this.quote(t, factory))
}
mainQueryOrder.push(this.quote(t, factory))
......
......@@ -1039,7 +1039,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
callback()
})
}, function() {done()})
}),
})
it('sorts by 2nd degree association', function(done) {
var self = this
......@@ -1084,6 +1084,29 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
}, function() {done()})
})
it('sorts by 2nd degree association with alias while using limit', function(done) {
var self = this
async.forEach([ [ 'ASC', 'Europe', 'France', 'Fred' ], [ 'DESC', 'Europe', 'England', 'Kim' ] ], function(params, callback) {
self.Continent.findAll({
include: [ { model: self.Country, include: [ self.Person, {model: self.Person, as: 'Residents' } ] } ],
order: [ [ { model: self.Country }, {model: self.Person, as: 'Residents' }, 'lastName', params[0] ] ],
limit: 3
}).done(function(err, continents) {
expect(err).not.to.be.ok
expect(continents).to.exist
expect(continents[0]).to.exist
expect(continents[0].name).to.equal(params[1])
expect(continents[0].countries).to.exist
expect(continents[0].countries[0]).to.exist
expect(continents[0].countries[0].name).to.equal(params[2])
expect(continents[0].countries[0].residents).to.exist
expect(continents[0].countries[0].residents[0]).to.exist
expect(continents[0].countries[0].residents[0].name).to.equal(params[3])
callback()
})
}, function() {done()})
})
}),
describe('ManyToMany', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!