From 57beefb894110d4bf73d672946399402a605e8af Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Tue, 9 Dec 2025 19:08:16 +0100 Subject: [PATCH] Fix query collision on i variable --- backend/api/package.json | 2 +- backend/api/src/get-profiles.ts | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/backend/api/package.json b/backend/api/package.json index 31711f5f..177089cd 100644 --- a/backend/api/package.json +++ b/backend/api/package.json @@ -1,7 +1,7 @@ { "name": "@compass/api", "description": "Backend API endpoints", - "version": "1.0.10", + "version": "1.0.11", "private": true, "scripts": { "watch:serve": "tsx watch src/serve.ts", diff --git a/backend/api/src/get-profiles.ts b/backend/api/src/get-profiles.ts index cedaee3c..0c5de074 100644 --- a/backend/api/src/get-profiles.ts +++ b/backend/api/src/get-profiles.ts @@ -111,7 +111,7 @@ export const loadProfiles = async (props: profileQueryType) => { FROM profile_${label} JOIN ${label} ON ${label}.id = profile_${label}.option_id GROUP BY profile_${label}.profile_id - ) i ON i.profile_id = profiles.id` + ) profile_${label} ON profile_${label}.profile_id = profiles.id` } const interestsJoin = getManyToManyJoin('interests') const causesJoin = getManyToManyJoin('causes') @@ -143,10 +143,10 @@ export const loadProfiles = async (props: profileQueryType) => { function getManyToManyClause(label: OptionTableKey) { return `EXISTS ( - SELECT 1 FROM profile_${label} pi2 - JOIN ${label} ii2 ON ii2.id = pi2.option_id - WHERE pi2.profile_id = profiles.id - AND ii2.name = ANY (ARRAY[$(values)]) + SELECT 1 FROM profile_${label} + JOIN ${label} ON ${label}.id = profile_${label}.option_id + WHERE profile_${label}.profile_id = profiles.id + AND ${label}.name = ANY (ARRAY[$(values)]) )` } @@ -278,9 +278,9 @@ export const loadProfiles = async (props: profileQueryType) => { } else if (orderByParam === 'last_online_time') { selectCols += ', user_activity.last_online_time' } - if (interests) selectCols += `, COALESCE(i.interests, '{}') AS interests` - if (causes) selectCols += `, COALESCE(i.causes, '{}') AS causes` - if (work) selectCols += `, COALESCE(i.work, '{}') AS work` + if (interests) selectCols += `, COALESCE(profile_interests.interests, '{}') AS interests` + if (causes) selectCols += `, COALESCE(profile_causes.causes, '{}') AS causes` + if (work) selectCols += `, COALESCE(profile_work.work, '{}') AS work` const query = renderSql( select(selectCols), @@ -291,7 +291,7 @@ export const loadProfiles = async (props: profileQueryType) => { limitParam && limit(limitParam), ) - console.debug('query:', query) + // console.debug('query:', query) const profiles = await pg.map(query, [], convertRow)