Skip to content

Commit 609b2f4

Browse files
committed
Do not return relation columns on parent when performing filter (due to joins).
1 parent 2d673b6 commit 609b2f4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ describe('DSSqlAdapter#findAll', function () {
168168
assert.equal(comments[0].content, 'test1');
169169
});
170170

171+
it('should not return relation columns on parent', function* () {
172+
var profile1 = yield adapter.create(Profile, { email: '[email protected]' });
173+
var user1 = yield adapter.create(User, {name: 'John', profileId: profile1.id});
171174

175+
var users = yield adapter.findAll(User, {'profile.email': '[email protected]'});
176+
assert.equal(users.length, 1);
177+
assert.equal(users[0].profileId, profile1.id);
178+
assert.isUndefined(users[0].email);
179+
});
172180

173181
});

0 commit comments

Comments
 (0)