Support for Polymorphic Associations
See original GitHub issueI have the following schema:
model Post {
id String @default(cuid()) @id
}
model Comment {
id String @default(cuid()) @id
}
model Vote {
id String @default(cuid()) @id
item Post | Comment
}
I’d like to associate the Vote model so that a vote an be created for a Post or a Comment.
As it stands now I have multiple models, PostVote and CommentVote which seems less than ideal.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:124
- Comments:40 (8 by maintainers)
Top Results From Across the Web
Polymorphic Associations - GitLab Docs
Rails makes it possible to define so called “polymorphic associations”. This usually works by adding two columns to a table: a target type...
Read more >Polymorphic associations - JavaLite
This defines polymorphic associations between models Classification, Mammal and Vehicle, such that the parent_type column of CLASSIFICATIONS table will contain ...
Read more >Polymorphic Associations - Sequelize
A polymorphic association consists on two (or more) associations happening with the same foreign key. For example, consider the models Image , Video...
Read more >Polymorphic association mappings of independent classes
A polymorphic association mapping supported by the JPA specification requires your classes to belong to the same inheritance hierarchy.
Read more >Rails Techniques: Using Polymorphic Associations - Semaphore
In Ruby on Rails, a polymorphic association is an Active Record association that can connect a model to multiple other models.
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 Free
Top 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

Here is a list of open issues I consider would make prisma a lot more appealing to companies with more complex needs. Most of them have suggestions and ideas on how to implement them.
Union Types: Every app comes to a point when some kind of feed or notification system is needed. So you have a model where the relation can be either A, B or C.
PostGIS: Any app working with some kind of geolocation.
Recursive Relations: Any app that has comments or product categories like an e-commerce.
Group by dates: Any app which wants to display a time based chart on the front-end, like a dashboard.
Soft deletes: Any app that don’t want to permanently delete records from the database or implement some kind of trash can.
These issues are old enough, useful enough and have enough likes to make it to the roadmap.
It’s funny, I was googling to see if this was solved yet and found the issue I opened. I ran into another instance where I need polymorphic relations.