Skip to content

Commit

Permalink
fix: sort not working (#657)
Browse files Browse the repository at this point in the history
* fix sort order, each sort parameter needs an explicit direction

* Remove eslint line disable

* Fix tests
  • Loading branch information
nickschot authored and zacharygolba committed Jan 21, 2017
1 parent 20eea5c commit ddbcd9e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/packages/database/query/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,9 @@ class Query<+T: any> extends Promise {
this.snapshots = this.snapshots
.filter(([method]) => method !== 'orderByRaw')
.concat([
// eslint-disable-next-line prefer-template
['orderByRaw', uniq([columnName, this.model.primaryKey])
.map(key => `${this.model.tableName}.${key}`)
.join(', ') + ` ${direction}`
.map(key => `${this.model.tableName}.${key} ${direction}`)
.join(', ')
]
]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/packages/database/test/query.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ describe('module "database/query"', () => {
const result = subject.order('createdAt', 'DESC').first();

expect(result.snapshots).to.deep.equal([
['orderByRaw', 'posts.created_at, posts.id DESC'],
['orderByRaw', 'posts.created_at DESC, posts.id DESC'],
['limit', 1]
]);
});
Expand Down Expand Up @@ -509,7 +509,7 @@ describe('module "database/query"', () => {
const result = subject.order('createdAt', 'DESC').last();

expect(result.snapshots).to.deep.equal([
['orderByRaw', 'posts.created_at, posts.id DESC'],
['orderByRaw', 'posts.created_at DESC, posts.id DESC'],
['limit', 1]
]);
});
Expand Down

0 comments on commit ddbcd9e

Please sign in to comment.