From 2ea56674213a5476acc8d85f2fcc791f9ed7577c Mon Sep 17 00:00:00 2001 From: Sean Lynch Date: Sun, 18 Oct 2015 09:40:18 -0400 Subject: [PATCH] Do not return relation columns on parent when performing filter (due to joins). --- src/index.js | 3 ++- test/findAll.spec.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 2460280..11664fe 100644 --- a/src/index.js +++ b/src/index.js @@ -20,7 +20,8 @@ function getTable (resourceConfig) { } function filterQuery (resourceConfig, params) { - let query = this.query.select('*').from(getTable(resourceConfig)) + let table = getTable(resourceConfig) + let query = this.query.select(`${table}.*`).from(table) params = params || {} params.where = params.where || {} params.orderBy = params.orderBy || params.sort diff --git a/test/findAll.spec.js b/test/findAll.spec.js index 4cbcfa7..43a92b9 100644 --- a/test/findAll.spec.js +++ b/test/findAll.spec.js @@ -172,4 +172,14 @@ describe('DSSqlAdapter#findAll', function () { var user = yield adapter.findAll(User, {limit: '10', offset: '20'}); }); + it('should not return relation columns on parent', function* () { + var profile1 = yield adapter.create(Profile, { email: 'foo@test.com' }); + var user1 = yield adapter.create(User, {name: 'John', profileId: profile1.id}); + + var users = yield adapter.findAll(User, {'profile.email': 'foo@test.com'}); + assert.equal(users.length, 1); + assert.equal(users[0].profileId, profile1.id); + assert.isUndefined(users[0].email); + }); + });