Skip to content

Commit

Permalink
Merge pull request #226 from afontainec/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
afontainec committed Aug 13, 2021
2 parents 2f359fc + 243bda5 commit 2a7de5b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions models/table.js
Expand Up @@ -421,6 +421,7 @@ class Table {
query.distinct(options.distinct);
options.clearSelect = true;
}
if (options.distinctOn) query.distinctOn(options.distinctOn);
if (options.clearSelect || (!Array.isArray(columns) && columns !== 'all')) return query;
if (!Array.isArray(columns)) columns = '*';
return query.select(columns);
Expand Down
12 changes: 12 additions & 0 deletions test/models/table/find/find2.js
Expand Up @@ -47,6 +47,18 @@ describe('TABLE GATEWAY: FIND', () => { // eslint-disable-line
assert.equal(keys.length, 5);
}
});


it('With distinctOn', async () => { // eslint-disable-line no-undef
await Coffee.save({ name: 'other', price: 99 });
const results = await Coffee.find({}, ['name', 'price'], { distinctOn: 'name', orderBy: ['name', ['price', 'asc']] });
const expected = [
{ name: 'expensive', price: 110 },
{ name: 'other', price: 99 },
{ name: 'this is the name', price: 100 },
];
assert.deepEqual(results, expected);
});
});

describe('Malicious happy path', () => { // eslint-disable-line
Expand Down

0 comments on commit 2a7de5b

Please sign in to comment.