My database stores data about a TV show. I want to store information about who worked on what episodes, and in what role.

Each crew member works on many episodes; each episode has many crew members; and crew members can work on the same episode in different roles (they can be writer and director on the same episode, for example). 

I'm new to thinking about ActiveRecord, so I'm a bit confused about how to properly represent these relationships in Rails. I would really love it if someone could tip me off as to the 'Rails way' to do this.

My instinct is to create a triple-join (or double-join; three fields, anyway) table. I have three models: `CrewMember` (has a name), `Episode` (has a title, airdate, etc), and `Role` (has a job title, like *Director*, *Writer* or *Actor*). I could create a table with three fields: `CrewMember_ID`, `Episode_ID`, and `Role_ID`. Each row would then describe someone working on a specific episode in a specific capacity.

So the relationship would appear to be:

* `CrewMember has_many :episodes`
* `Episode has_many :crew_members`
* `CrewMember has_many :roles`
* `Role has_many :crew_members`.

Here's where I get confused. Do I create a new model for that table? And if I do, how exactly do I create instances of that object? I understand relationships like *Author has\_many :books* where I can create a book with `Author.books.new`, but this kind of has-many has-many has-many thing stumps me a bit.

I can do what I want with SQL, I'm just having trouble approaching it from an ORM/ActiveRecord angle.