Support recursive relationships
See original GitHub issueProblem
Let’s say I have a table called categories
. This table can refer to itself as a foreign key with parentCategory
.
So a categories can have many subcategories, and subcategories can also have subcategories, with an unlimited combination. The idea is to support recursive queries to easily query them along with their sub categories.
Suggested solution
Some valid implementation of something similar to Postgres WITH RECURSIVE
https://www.postgresqltutorial.com/postgresql-recursive-query/
Alternatives
N/A
Additional context
N/A
Issue Analytics
- State:
- Created 3 years ago
- Reactions:117
- Comments:29 (1 by maintainers)
Top Results From Across the Web
Recursive Relationships in ER diagrams - GeeksforGeeks
A relationship between two entities of a similar entity type is called a recursive relationship. Here the same entity type participates more ...
Read more >Recursive Relationships - erwin, Inc.
A recursive relationship is a non-identifying relationship between two entities or tables that represents the fact that one company can own another company....
Read more >Recursive Relationship - an overview | ScienceDirect Topics
Recursive relationships represent self-referencing or involuting relationships. ... The original ER model supports N-ary relationships.
Read more >7.4.4: Recursive Relationships - eCampusOntario Pressbooks
A relationship is recursive if the same entity type appears more than once. A typical business example is a rule such as “an...
Read more >Chapter 6 One-to-One and Recursive Relationships
A recursive relationship is within a single entity rather than between entities. Recursive relationships are mapped to the relational model in the same...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
If the Prisma team is looking for a real-world example then I have one!
Here’s a schema with a
Post
model which has repies and also a root post. The reason it’s done this way is so there doesn’t need to be a separate model for “threads” and “posts” it’s all just a “post” and “first” indicates if it’s the first post in a thread.And here’s a recursive CTE used to count the number of replies to threads (posts with “first” set to true)
If this could be expressed purely via Prisma, that would be awesome! I already hate the complexity and lack of composability with SQL syntax, but recursive CTEs are a special kind of hell!
I haven’t had an issue with recursive relationships in the schema, but querying them is the feature we’re looking for. How do you query your categories, since the depth is unknown?