adonis-lucid-polymorphic icon indicating copy to clipboard operation
adonis-lucid-polymorphic copied to clipboard

morphToMany / morphedByMany ?

Open willvincent opened this issue 6 years ago • 3 comments

As far as I can tell this is not already supported...

Can we add the ability to define a pivot table for polymorphic relations?

For the use case of; a single shared list of tags, that can be applied to multiple content types.

ie:

tags:

  • technology
  • science
  • entertainment

content types:

  • blog post
  • video
  • article

multiple blog posts, videos and articles might all be tagged with 'science' but 'science' should only exist as a tag one time, and simply be referenced multiple times as one does with a regular many to many relationship utilizing a pivot table.

I suppose a workaround might be just to make the 'taggable' pivot table an actual model, and then setup 1:many relationships between it and tags, and regular polymorphic relations between taggable and the various content types.

Would be nice to not have to make taggable a model though. Here's an example of how it's done in laravel for reference: https://itsolutionstuff.com/post/laravel-many-to-many-polymorphic-relationship-tutorialexample.html

willvincent avatar Oct 15 '18 15:10 willvincent

@willvincent It's planned in next release. At the moment, it was necessary to provide support for adonis framework 4.1.x. Thanks for feedback.

enniel avatar Oct 15 '18 18:10 enniel

Hey @enniel would you like if I write a PR for this?

jpcbarros avatar Jul 04 '19 13:07 jpcbarros

@jpcbarros @willvincent have any of you found any workarounds for this situation?

JhonatanPereira avatar Mar 04 '22 15:03 JhonatanPereira