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 (#354)
  • Loading branch information
juanmahidalgo committed Oct 3, 2023
1 parent c8027fa commit e075ae0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions 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[], items.id) `
return SQL`ORDER BY array_position(${filters.ids}::text[], id) `
}

let sortByQuery:
Expand Down Expand Up @@ -316,7 +316,7 @@ const getWhereWordsJoin = (category: CatalogQueryFilters['category']) => {
const getMetadataJoins = (schemaVersion: string) => {
return SQL` LEFT JOIN (
SELECT
metadata.id,
metadata.id as metadata_id,
wearable.description,
wearable.category,
wearable.body_shapes,
Expand All @@ -331,10 +331,10 @@ JOIN `
.append(schemaVersion)
.append(
`.metadata_active AS metadata ON metadata.wearable = wearable.id
) AS metadata_wearable ON metadata_wearable.id = items.metadata AND (items.item_type = 'wearable_v1' OR items.item_type = 'wearable_v2' OR items.item_type = 'smart_wearable_v1')
) AS metadata_wearable ON metadata_wearable.metadata_id = items.metadata AND (items.item_type = 'wearable_v1' OR items.item_type = 'wearable_v2' OR items.item_type = 'smart_wearable_v1')
LEFT JOIN (
SELECT
metadata.id,
metadata.id as metadata_id,
emote.description,
emote.category,
emote.body_shapes,
Expand All @@ -353,7 +353,7 @@ JOIN `
.append(schemaVersion)
.append(
`.metadata_active AS metadata ON metadata.emote = emote.id
) AS metadata_emote ON metadata_emote.id = items.metadata AND items.item_type = 'emote_v1' `
) AS metadata_emote ON metadata_emote.metadata_id = items.metadata AND items.item_type = 'emote_v1' `
)
}

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[], items.id) `
`ORDER BY array_position($1::text[], id) `
)
expect(orderBy.values).toContain(ids)
})
Expand Down

0 comments on commit e075ae0

Please sign in to comment.