1 year ago

Inverse Polymorphic one-to-many

Posted 1 year ago by PiotrG

I've been trying to understand how to implement this or if I am just over-complicating things in my head.

I have a model called Group. I would like to be able to assign many different models to this group.

Of course I could set up a One-to-Many for each model to Group but I am thinking it would be more efficient to be able to assign any number of different models without having to configure each as One-To-Many and thereby having separate tables for each.

The examples in the Laravel Docs show the opposite. Many different models can have have "groupable" relationships, but I only want a Model to have 1 group.


Groups Table: Group ID;Group Name;Model Type;Model ID 1;My Group;App\Book;5 2;My Second Group;App\Video;7 1;My Group;App\Book;8

Am I going about this the wrong way? I feel I'm missing something...

Please sign in or create an account to participate in this conversation.