Hello,
I’m trying to figure out how to do Polymorphic relations.
I know Sequelize does support this.
I see the “Collection Selector”, and I know there are the Comments and Approval workflow plugins, which I presume makes use of polymorphic relations.
So it seems like the fundamentals are there. But I can’t find any documentation on how to implement my own polymorphic systems, and I can’t find a plugin that does this either.
How do I do Polymorphic Relations?
For example: a “Booking” BelongsTo (m2o) → “Staff” “Freelancer” “Client” “Supplier” etc.
The related data is wildly unrelated, but I need status relating to the booking of the related model.
Ok, I spun up a testing environment.
Am I right that this requires the use of Inheritance?
So a “Staff” “Freelancer” etc has to inherit from a “Bookable” table.
A “Booking” has a relation to the “Bookable” table to be able to associate any of the “Staff” “Freelancer” etc tables.
If I store a “type” field as a “select collection” on the “Booking” table, then I can filter bookings to specifically staff or freelancers, and I can choose how the “current record” is interpreted (as a “Staff” “Freelancer” etc in order to access further details).
So, I think I have figured out my previous question, somewhat.
I think I am now stuck on how to create a generic “more details” drawer.
So I have a table of bookings that has a column of bookables inherited name field as the column’s Title. Clicking on the name field opens up a drawer.
But I can’t seem to find a way to apply linkage rules to entire blocks within a drawer, ie “if type is freelancer, show freelancer details and hide the others”.
Any hints on how to do that?
Also, it would be amazing if the documentation could be extended to include how to work with polymorphism.
Cheers!
Ah, I have figured it out.
In the Action column:
add a View for each type of polymorphic collection, then changing the linkage rules on those view actions to only be visible if the Booking type (collection select) matches what the drawer/dialog/page is designed for.
A Details/Form view of the specific relation in the popup/drawer/page then has to have its data scope set to show the relevant record(s).
It’s pretty clunky to set up and edit, but does seem to work.
I don’t think it’s going to scale well, but thankfully I don’t foresee this having to grow beyond the initial scope (famous last words).
EDIT:
Sorry for the chain of posts.