Skip to content

Commit

Permalink
Fixed issue where using $select with a composite PK returns a databas…
Browse files Browse the repository at this point in the history
…e error (#140)

Co-authored-by: David Farrugia <david.farrugia@sagossgroup.com>
  • Loading branch information
davidf84 and David Farrugia committed Feb 8, 2021
1 parent eefefc9 commit a274ff7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class Service extends AdapterService {

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

for (const [key, item] of Object.entries(items)) {
const matches = item.match(/^ref\((.+)\)( as (.+))?$/);
Expand Down
14 changes: 14 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,20 @@ describe('Feathers Objection Service', () => {
});
});
});

it('allows get queries with $select', () => {
return peopleRooms.get([2, 2], { query: { $select: ['admin'] } }).then(data => {
expect(data.admin).to.equal(1);
});
});

it('allows find queries with $select', () => {
return peopleRooms.find({ query: { roomId: 2, $select: ['admin'] } }).then(data => {
expect(data.length).to.equal(2);
expect(data[0].admin).to.equal(0);
expect(data[1].admin).to.equal(1);
});
});
});

describe('Eager queries', () => {
Expand Down

0 comments on commit a274ff7

Please sign in to comment.