Skip to content

Commit

Permalink
Apply distinct on primary key field in subqueries
Browse files Browse the repository at this point in the history
  • Loading branch information
licitdev committed Aug 8, 2022
1 parent 95ad5c7 commit bbe7cb9
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/src/utils/apply-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ export function applyFilter(
const subQueryBuilder = (filter: Filter) => (subQueryKnex: Knex.QueryBuilder<any, unknown[]>) => {
subQueryKnex
.select({ [schema.collections[collection].primary]: column })
.distinctOn(column)
.from(collection)
.whereNotNull(column);

Expand Down Expand Up @@ -427,6 +428,7 @@ export function applyFilter(

subQueryKnex
.select({ [field]: column })
.distinctOn(`${collection}.${schema.collections[collection].primary}`)
.from(collection)
.whereNotNull(column);

Expand Down

0 comments on commit bbe7cb9

Please sign in to comment.