Skip to content
Advertisement

How to establish a one-to-many relationship to a model whose type is stored in db

I have a database that looks like this: Database Graphical Representation

The dance_performer.perfomer_type field hosts values such at 'AppDancer', 'AppCouple' or 'AppFormation'.

How would you proceed to connect the dance_performer.perfomer_id to the different models? I am not sure how I am supposed to write the relationships in the different models. Should I create a AppPerformer model which would then direct to one of the three previously mentioned?

I would appreciate the help.

Advertisement

Answer

You are looking for polymorphic relationships. See documentations https://laravel.com/docs/7.x/eloquent-relationships#polymorphic-relationships

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement