Skip to content
This repository was archived by the owner on Sep 2, 2025. It is now read-only.

Commit a274ff7

Browse files
davidf84David Farrugia
andauthored
Fixed issue where using $select with a composite PK returns a database error (#140)
Co-authored-by: David Farrugia <[email protected]>
1 parent eefefc9 commit a274ff7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class Service extends AdapterService {
358358

359359
_selectQuery (q, $select) {
360360
if ($select && Array.isArray($select)) {
361-
const items = $select.concat(`${this.Model.tableName}.${this.id}`);
361+
const items = $select.concat(Array.isArray(this.id) ? this.id.map(el => { return `${this.Model.tableName}.${el}`; }) : `${this.Model.tableName}.${this.id}`);
362362

363363
for (const [key, item] of Object.entries(items)) {
364364
const matches = item.match(/^ref\((.+)\)( as (.+))?$/);

test/index.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,20 @@ describe('Feathers Objection Service', () => {
619619
});
620620
});
621621
});
622+
623+
it('allows get queries with $select', () => {
624+
return peopleRooms.get([2, 2], { query: { $select: ['admin'] } }).then(data => {
625+
expect(data.admin).to.equal(1);
626+
});
627+
});
628+
629+
it('allows find queries with $select', () => {
630+
return peopleRooms.find({ query: { roomId: 2, $select: ['admin'] } }).then(data => {
631+
expect(data.length).to.equal(2);
632+
expect(data[0].admin).to.equal(0);
633+
expect(data[1].admin).to.equal(1);
634+
});
635+
});
622636
});
623637

624638
describe('Eager queries', () => {

0 commit comments

Comments
 (0)