Skip to content

Commit 54e9910

Browse files
committed
Merge pull request #24 from techniq/relation-columns
Do not return relation columns on parent when performing filter
2 parents 71a5c75 + 2ea5667 commit 54e9910

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ function getTable (resourceConfig) {
2020
}
2121

2222
function filterQuery (resourceConfig, params) {
23-
let query = this.query.select('*').from(getTable(resourceConfig))
23+
let table = getTable(resourceConfig)
24+
let query = this.query.select(`${table}.*`).from(table)
2425
params = params || {}
2526
params.where = params.where || {}
2627
params.orderBy = params.orderBy || params.sort

test/findAll.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,14 @@ describe('DSSqlAdapter#findAll', function () {
172172
var user = yield adapter.findAll(User, {limit: '10', offset: '20'});
173173
});
174174

175+
it('should not return relation columns on parent', function* () {
176+
var profile1 = yield adapter.create(Profile, { email: '[email protected]' });
177+
var user1 = yield adapter.create(User, {name: 'John', profileId: profile1.id});
178+
179+
var users = yield adapter.findAll(User, {'profile.email': '[email protected]'});
180+
assert.equal(users.length, 1);
181+
assert.equal(users[0].profileId, profile1.id);
182+
assert.isUndefined(users[0].email);
183+
});
184+
175185
});

0 commit comments

Comments
 (0)