Skip to content
Snippets Groups Projects

조합 필터링 로직 수정

Merged Lee WooChang requested to merge fix/filtered-combination into main
1 file
+ 15
9
Compare changes
  • Side-by-side
  • Inline
+ 15
9
@@ -72,18 +72,24 @@ const PartRepository = {
async getFilteredCombinations(queryValues) {
const query = `
SELECT
c.id AS combination_id,
array_agg(r.part_id) AS partIds
FROM combinations c
LEFT JOIN relations r ON c.id = r.combination_id
WHERE r.combination_id IN (
SELECT DISTINCT combination_id
WITH input_parts AS (
SELECT array_agg(unnest) AS required_parts
FROM unnest($1::int[]) AS unnest
),
parts AS (
SELECT
combination_id,
array_agg(part_id ORDER BY part_id) AS existing_parts
FROM relations
WHERE part_id = ANY($1::int[])
GROUP BY combination_id
)
GROUP BY c.id;
SELECT
p.combination_id,
p.existing_parts AS partIds
FROM parts p, input_parts i
WHERE p.existing_parts @> i.required_parts;
`;
const result = await pool.query(query, queryValues);
return result.rows;
},
Loading