@loomcore/api 0.1.98 → 0.1.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -24,7 +24,16 @@ export function buildJoinClauses(operations, mainTableName) {
|
|
|
24
24
|
const localRef = resolveLocalField(operation.localField, mainTableName);
|
|
25
25
|
const foreignSnake = convertFieldToSnakeCase(operation.foreignField);
|
|
26
26
|
const joinType = operation instanceof InnerJoin ? "INNER JOIN" : "LEFT JOIN";
|
|
27
|
-
|
|
27
|
+
if (operation instanceof LeftJoinMany) {
|
|
28
|
+
joinClause += ` ${joinType} (
|
|
29
|
+
SELECT "${foreignSnake}", json_agg(row_to_json(_many.*)) AS aggregated
|
|
30
|
+
FROM "${operation.from}" _many
|
|
31
|
+
GROUP BY "${foreignSnake}"
|
|
32
|
+
) AS ${operation.as} ON ${localRef} = ${operation.as}."${foreignSnake}"`;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
joinClause += ` ${joinType} "${operation.from}" AS ${operation.as} ON ${localRef} = ${operation.as}."${foreignSnake}"`;
|
|
36
|
+
}
|
|
28
37
|
}
|
|
29
38
|
}
|
|
30
39
|
return joinClause;
|