Design Question: How do you handle many-to-many relationships with additional fields

I actually do many_to_many and has_many at the same time for one table.

An example would be the actor schema will have a many_to_many association with movies and also have a has_many to the join table between actor schema and movie schema. The movie table will have a many_to_many with actor schema and a has_many with the join table between actor and movie. The join table will have two has_many association, one for actor schema and the other for movie schema.

It works out pretty great. The many_to_many relationship gives me a lot of flexibility so most of my tables are many_to_many relationship.

If I want to look up a field in the join table, I just preload the join table and access the field.

1 Like