From ddbcd9e43b143dffd82fa0726f067829ff044592 Mon Sep 17 00:00:00 2001 From: Nick Schot Date: Sat, 21 Jan 2017 21:22:40 +0100 Subject: [PATCH] fix: sort not working (#657) * fix sort order, each sort parameter needs an explicit direction * Remove eslint line disable * Fix tests --- src/packages/database/query/index.js | 5 ++--- src/packages/database/test/query.test.js | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/packages/database/query/index.js b/src/packages/database/query/index.js index 321cc57c..1df7bd9a 100644 --- a/src/packages/database/query/index.js +++ b/src/packages/database/query/index.js @@ -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(', ') ] ]); } diff --git a/src/packages/database/test/query.test.js b/src/packages/database/test/query.test.js index 20b4882e..bdcbf41f 100644 --- a/src/packages/database/test/query.test.js +++ b/src/packages/database/test/query.test.js @@ -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] ]); }); @@ -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] ]); });