Relationships: Polymorphic Types
See original GitHub issuemodel report {
id String @id
message String
reportable @morphRelation(models: [User, Post])
}
model User {
id String @id
name String
}
model Post {
id String @id
content String
}
When adding a “morph map” to your existing application, every morphable *_type column value in your database that still contains a fully-qualified class will need to be converted to its “map” name.
reference👉https://laravel.com/docs/8.x/eloquent-relationships#custom-polymorphic-types
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Re-Introducing Eloquent's Polymorphic Relationships - SitePoint
A polymorphic relationship is where a model can belong to more than one other model on a single association. To clarify this, let's...
Read more >Polymorphic relationships in Laravel and their use cases
The general concept behind using polymorphic relationships revolves around identifying similarities between what two or more models might need ...
Read more >Eloquent: Relationships - The PHP Framework For Web Artisans
One To Many (Polymorphic); Many To Many (Polymorphic). Defining Relationships. Eloquent relationships are defined as methods on your Eloquent model classes.
Read more >Understanding Relationship Fields and Polymorphic Fields
In a polymorphic relationship, the referenced object of the relationship can be one of several different types of object. Some fields are relationship...
Read more >4.9. Polymorphic Relationships - JPA Objects -
A polymorphic relationship is one where the referenced type could be any entity. For example, a class that has a property of type...
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
I think a common use case for this would be something like an activity feed. Imagine a platform-like site where people can post, comment, like, etc. It would be nice to have a model like:
And in the client, we would be able to make a request like
prisma.activity.findMany({ include: { model: true }})
and get the Comment, Like, or Post back with each Activity, without having to specify all of the possible relations everywhere an Activity will be called.Ok, actually found the duplicate issue for this: https://github.com/prisma/prisma/issues/2505
I knew it existed. Sorry for linking the interface one at first.
Add your proposal and +1 to that issue.