Skip to content

Commit

Permalink
fix: order by alias should not throw (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyjake authored Jan 6, 2022
1 parent 931cd81 commit d8deacb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/drivers/abstract/spellbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function createSubspell(spell) {
subspell.orders = [];
for (const order of orders) {
const [token, direction] = order;
const { type, qualifiers, value } = token;
const { type, qualifiers = [], value } = token;
if (type == 'id' && qualifiers[0] == baseName) {
subspell.orders.push([{ type, value }, direction]);
}
Expand Down Expand Up @@ -220,7 +220,7 @@ function formatSelectWithJoin(spell) {

let hoistable = skip > 0 || rowCount > 0;
if (hoistable) {
function checkQualifier({ type, qualifiers }) {
function checkQualifier({ type, qualifiers = [] }) {
if (type === 'id' && qualifiers.length> 0 && !qualifiers.includes(baseName)) {
hoistable = false;
}
Expand Down
5 changes: 5 additions & 0 deletions test/integration/suite/associations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,9 @@ describe('=> Associations order / offset / limit', function() {
// both posts have comments with content containing `oo` but only one should return
assert.equal(posts.length, 1);
});

it('should not throw if select and order by alias', async function() {
const result = await Post.include('comments').select('content as cnt').order('cnt', 'desc').limit(1);
assert.equal(result.length, 1);
});
});

0 comments on commit d8deacb

Please sign in to comment.