I
I
Ichi Nya2021-08-27 19:49:38
Software design
Ichi Nya, 2021-08-27 19:49:38

Laravel pivot or model when linking three tables, which is better to use?

The question is which is better to use.

For example, let's take a movie database:
table movie (movies)
id
name

table person (people - actors, screenwriters, operators and others)
id
name

table role (role - actor, screenwriter, make-up artist)
id
name

How best to link them to determine the role. For example, in a film, the actor and screenwriter may be the same person.
Alternatively pivot:
movie_id, role_id, person_id

You can create a separate model like PersonRole:
id, role_id, person_id
and pivot: movie_id, person_role_id

Which would be better? Or is it implemented in some other way? Interested from the point of building architecture.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2021-08-27
@jazzus

movie_person (movie_id person_id) person_role (person_id role_id)
bind all belongsToMany.
Only I would rename the role. it's closer to system user roles, not content.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question