Commit d309c8c3 authored by Fabien Manière's avatar Fabien Manière

get recursive parents query: invert sql results

parent 8425e355
Pipeline #5203 failed with stages
in 18 minutes and 14 seconds
......@@ -397,15 +397,16 @@ recursiveParents :: NodeId
-> Cmd err [DbTreeNode]
recursiveParents nodeId nodeTypes = map (\(nId, tId, pId, n) -> DbTreeNode nId tId pId n)
<$> runPGSQuery [sql|
WITH RECURSIVE recursiveParents AS(
SELECT id, typename, parent_id, name
FROM public.nodes WHERE id = ?
UNION ALL
SELECT n.id, n.typename, n.parent_id, n.name
FROM public.nodes n
INNER JOIN recursiveParents rp ON n.id = rp.parent_id
WHERE n.typename IN ?
) SELECT * FROM recursiveParents;
WITH RECURSIVE recursiveParents AS
(
SELECT id, typename, parent_id, name, 1 as original_order
FROM public.nodes WHERE id = ?
UNION ALL
SELECT n.id, n.typename, n.parent_id, n.name, rp.original_order+1
FROM public.nodes n
INNER JOIN recursiveParents rp ON n.id = rp.parent_id
WHERE n.typename IN ?
) SELECT id, typename, parent_id, name FROM recursiveParents ORDER BY original_order DESC;
|] (nodeId, In typename)
where
typename = map nodeTypeId ns
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment