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

get recursive parents query: invert sql results

parent 8425e355
...@@ -397,15 +397,16 @@ recursiveParents :: NodeId ...@@ -397,15 +397,16 @@ recursiveParents :: NodeId
-> Cmd err [DbTreeNode] -> Cmd err [DbTreeNode]
recursiveParents nodeId nodeTypes = map (\(nId, tId, pId, n) -> DbTreeNode nId tId pId n) recursiveParents nodeId nodeTypes = map (\(nId, tId, pId, n) -> DbTreeNode nId tId pId n)
<$> runPGSQuery [sql| <$> runPGSQuery [sql|
WITH RECURSIVE recursiveParents AS( WITH RECURSIVE recursiveParents AS
SELECT id, typename, parent_id, name (
FROM public.nodes WHERE id = ? SELECT id, typename, parent_id, name, 1 as original_order
UNION ALL FROM public.nodes WHERE id = ?
SELECT n.id, n.typename, n.parent_id, n.name UNION ALL
FROM public.nodes n SELECT n.id, n.typename, n.parent_id, n.name, rp.original_order+1
INNER JOIN recursiveParents rp ON n.id = rp.parent_id FROM public.nodes n
WHERE n.typename IN ? INNER JOIN recursiveParents rp ON n.id = rp.parent_id
) SELECT * FROM recursiveParents; WHERE n.typename IN ?
) SELECT id, typename, parent_id, name FROM recursiveParents ORDER BY original_order DESC;
|] (nodeId, In typename) |] (nodeId, In typename)
where where
typename = map nodeTypeId ns 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