-
-
Notifications
You must be signed in to change notification settings - Fork 611
Open
Labels
Description
Summary
This plugin generates two different SQLs one for parent (chat) and one for the "profiles" in which case the SQL of the "profiles" can't access the alias "chat" as it's executed in a different query. Wrapping the "$chatId" inside $profiles.placeholder($chatId, TYPES.bigint) solves the issue by passing "chatId" as param.
const $profiles = profiles.find();
const $chatId = $chat.get('chat_id');
$profiles.where(
sql.fragment`${$profiles.alias}.user_id in (
select user_id from public.participants where chat_id = ${$chatId}
)`
);
return $profiles;Expected results
It would be better to inline this query in the original SQL query instead of executing new query.
Actual results
Reproducible
The plan generates a different SQL query.
Additional context
From the conversation of the discord chat the ordering of calling toSQL being called vs the fragment embedding can be reconsidered to solve this issue and allow to use the $chatId without having to wrap it into "placeholder".