sequelize/sequelize
View on GitHubIncorrect ordering for a findAll operation on a scoped model with predefined order
Open
#11415 opened on Sep 10, 2019
good first issuestatus: wiptype: bug
Description
What are you doing?
I have a Model TheModel with a scope scoped containing order , say order1.
On invoking a findAll with an order, say order2, the resulting order is order1, order2
// MINIMAL, SELF-CONTAINED code here (SSCCE/MCVE/reprex)
TheModel.addScope('scoped', {
order: [
[associatedModel1, 'foo', 'ASC'],
[associatedModel2, 'bar', 'ASC'],
]
});
scopedModel.findAll({
order: [
['field1', 'ASC'],
[associatedModel1, 'foo', 'ASC'],
]
});
What do you expect to happen?
Resulting order: ORDER BY field1 ASC, associatedModel1.foo ASC
(This was the actual order using sequelize version 3.30.4)
What is actually happening?
Resulting order: ORDER BY associatedModel1.foo ASC, associatedModel2.bar ASC, field1 ASC, associatedModel1.foo ASC
Environment
- Sequelize version: 5.15.2
- Node.js version: 6.13.4
- Operating System: XXX
- If TypeScript related: TypeScript version: XXX
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s):
- I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don't know how to start, I would need guidance.
- No, I don't have the time, although I believe I could do it if I had the time...
- No, I don't have the time and I wouldn't even know how to start.
Note: I was able to come to this line which is merging the two orders. However, I think the community needs to collectively decide what should be the expected behaviour. I think that the order provided by findAll should always override the scope order.