Polymorphic relation

System Information
  • Strapi Version: 4
  • Operating System:
  • Database:
  • Node Version:
  • NPM Version:
  • Yarn Version:

How to create polymorphic relation in v4?

As far as I understand, polymorphic relations are not ready to use yet as of version 4.0.2. They were not yet added to the v4 documentation and seem not to work smoothly so far.

The database layer appears quite ready and is already used by the file type in the upload plugin. However, currently the default controller strips off the relations during sanitizing the entities (at least for the morphOne and morphMany relation types).

@Mohammad_Ashenab, did you find any working solutions?

@DMehaffy, are contributions welcome regarding these issues or is this still work in progress by the strapi team?

I believe for new feature dev @gtitze we are open to contribution but it would need to go through our rfcs process first: GitHub - strapi/rfcs: RFCs for Strapi future changes

@DMehaffy, well I think this would not be a new feature at all, because the basics are already there implemented in the core and work just fine. However, the sanitizing in the controller is buggy and renders the otherwise working technology useless.

Checking the code indicated, that it should already work. I tested it and disabled the sanitizing of the content and all functionality just works as I expected it.

Therefore, I think it would be a bugfix for the content sanitizer and nothing else. Beyond that, tests and documentation might be a good add-on for PRs.

Thus, is a RFC still for a bugfix? And is a PR welcome for fixing this? Just want to avoid creating a PR that won’t be considered anyway.

Polymorphic relations have never been handled properly, there were purpose designed originally for the upload plugin and then later for dynamic zones.

It should still need to go through an RFC to approve implementation strat before a PR. RFCs aren’t just exclusive to feature requests. Its any topic that spans multiple points of interaction. simply fixing the content sanitizer is not enough to bring support for polymorphic relations.

There is the CTB and CTM to think about, referencing and storing in the schema files, database layer support, plugins, ect.

Hey there!

Is there any follow-up on this? We would love to have the ability to make a relation that points out to different collection types.

Thank you!