question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for Polymorphic Associations

See original GitHub issue

I 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:open
  • Created 4 years ago
  • Reactions:124
  • Comments:40 (8 by maintainers)

github_iconTop GitHub Comments

108reactions
brielovcommented, Apr 5, 2022

Make sure all the things you mention have good features requests with good use case description and optimally potential APIs and designs - the better and easier it is to understand a feature, the easier time we have when we tackle these.

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.

65reactions
lukehamiltoncommented, Jun 28, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found