0

Laravel doc provides polymorphic "many-to-many" sample (pivot table taggables) with the following structure:

taggables
    tag_id - integer
    taggable_id - integer
    taggable_type - string

Here only one side is polymorphic (taggable_*). My case is:

  • "instances" model family contains "field", "event" etc
  • "templates" model family contains "template_field", "template_event" etc
  • pivot table structure is:
template_registry:
    id
    instance_type - string
    instance_id - integer
    template_type - string
    template_id - integer

Which PHP code required to get something like:

$field->template

where template get linked template object (template_field / template_event)

4
  • to me it looks like the instance should be related to the template Commented Jun 5, 2024 at 12:25
  • @apokryfos Little bit complex - (field or event or ...) should be related to (template_*) Commented Jun 5, 2024 at 12:54
  • does a field relate to template_events or only template_fields? Commented Jun 5, 2024 at 13:16
  • @krisgjika yes, field -> template_field, event -> template_event, twin -> template_twin. Strongly, pivot table is not required: "template_id" field in table "field" more than enough. But for some reasons (to get common API) I have to use pivot table Commented Jun 5, 2024 at 13:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.