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.

Relationships: Polymorphic Types

See original GitHub issue
model 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:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
laugharncommented, Nov 9, 2020

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:

model Activity {
  id String @id
  model @morphRelation(models: [Comment, Like, Post])
}

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.

0reactions
pantharshit00commented, Nov 10, 2020

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.

Read more comments on GitHub >

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

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