It is possible to do CTE table query with ROM SQL or we have to handle it at the Sequel level?
I didn’t find anything on the source code of the gem so I am asking.
And if no, what would be the steps to implement it?
Is on the fly relations possible?
Example of what I want to build :
WITH RECURSIVE hierarchical_cte (level_id, parent_id, level) AS
(
SELECT hierarchical.level_id, hierarchical.parent_id, hierarchical.level
FROM hierarchical
WHERE hierarchical.level_id = '1_1_2'
UNION ALL
SELECT hierarchical.level_id, hierarchical.parent_id, hierarchical.level
FROM hierarchical_cte
JOIN hierarchical ON hierarchical_cte.parent_id = hierarchical.level_id
) SELECT * FROM hierarchical_cte;
The method spends most of the time building up the different parts of the query then finally executes it.
It’s relevant to me to get this information grouped by project_id (so I can then show the top contributors to each project), so I then group the result at the end.
I know this is an old post but this may help future readers. Avoid using self referencing tables (parent_id) for hierarchies. I attempted this design using ROM and it turns into a hairy mess! Sometimes this could be considered an anti-pattern. Try something called a Closure Table. This was easy to implement with ROM and solves a lot of other issues like having N number of nested joins for each level.