Manual relationship with recursive CTE
I'm trying to implement this comment/thread (https://discord.com/channels/711271361523351632/1110614023881359430/1111297127897890866) and creating a manual relationship with a recursive CTE (for a tag in a graph structure, get all parent tags). I'm able to get it done with Ecto spitting out grouped map lists. I'm getting a bit stuck figuring out how to get them as an Ash Resource in the end.
Is there anything major I'm missing?
Results look like:
8 Replies
I’ve done this recently. If you can wait until Monday I’ll dig it up for you.
It can definitely wait till then. Have a great weekend! 🙂
You too!
@skander I had half-written a blog post about it, but never got it finished. I've posted the WIP blog post and the redacted final code. I hope it's helpful. https://gist.github.com/jimsynz/9557a2ad3ec23693f06f8588ba7ed57d
Gist
A half-finished blog post about using recursive CTEs with Ash.
A half-finished blog post about using recursive CTEs with Ash. - ash_recursive_cte_wip.md
Thank you so much! It’s still Sunday night here so I’ll be checking this tomorrow. Appreciate it!
all good 🙂
That worked! Thank you so much. I made a couple modifications so that the query would load all relationships in a batch, then group by the original resource's ID
The rest is the same. The key for me here was not knowing you could pass a tuple into
select
and recursive_ctes
Appreciate the help!My pleasure