Skip to content

Commit

Permalink
fix: fix ambiguous id ORDER in the catalog query when filtering by te…
Browse files Browse the repository at this point in the history
…xt (#353)

* fix: fix ambiguous id ORDER in the catalog query when filtering by text

* test: fix broken test
  • Loading branch information
juanmahidalgo committed Oct 3, 2023
1 parent 6b10bdf commit c8027fa
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ports/catalog/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function getOrderBy(filters: CatalogFilters) {

if (search) {
// If the filters have a search term, we need to order by the position of the item in the search results that is pre-computed and passed in the ids filter.
return SQL`ORDER BY array_position(${filters.ids}::text[], id) `
return SQL`ORDER BY array_position(${filters.ids}::text[], items.id) `
}

let sortByQuery:
Expand Down
2 changes: 1 addition & 1 deletion src/tests/ports/catalog-queries.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ test('catalog utils', () => {
it('should ORDER BY the ids order in the array', () => {
const orderBy = getOrderBy({ search, ids }) as SQLStatement
expect(orderBy.text).toContain(
`ORDER BY array_position($1::text[], id) `
`ORDER BY array_position($1::text[], items.id) `
)
expect(orderBy.values).toContain(ids)
})
Expand Down

0 comments on commit c8027fa

Please sign in to comment.