Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Active Record Associations in Rails More Association Options Polymorphic Options

Natalie Tan
Natalie Tan
25,519 Points

Poloymorphic Options in Rails

I was watching this video on polymorphic options https://teamtreehouse.com/library/polymorphic-options

I felt like the model used to demonstrate this concept was questionable.

Whilst both movies & shows can have many_actors through a "production", actors can also act in many movies & shows, and technically do not "belong_to" a production.

In reality, shouldn't that be a many to many relationship?

1 Answer

Hi Natalie,

I see what you mean. The scenario they used is a bit confusing. The only way to have a many-to-many relationship is via a join table. A join table is basically just a table of foreign keys for each member of the relationship. If there is no join table, it can't be many-to-many. I hope that helps. Happy coding.

Natalie Tan
Natalie Tan
25,519 Points

Yup, i understand that they didn't code it to be a many-to-many example in the video. I'm just not sure why they chose to use a polymorphic relationship in this example.

I just understood the real world relationship between actors <--> movies , actors <--> shows. to be something like that:

Show & Movie Single Table Inheritance through Production

Show < Production

Movie < Production

Production

has_many : roles

has_many :actors, through :roles

Role

belongs_to :actor

belongs_to :production

Actor

has_many : roles

has_many :productions, through :roles