I've been applying has and belongs to many
style associations to a project I've been working on, but because I wanted to capture extra information in my join model, I'm implicitly setting it up via the more elaborate belongs_to
/has_many
approach instead of has_and_belongs_to_many
. After initially stumbling on this, I learned that I needed both of these definitions in my model User (and the same in the Show model counterpart):
has_many :saved_shows
has_many :shows, :through :saved_shows
Everything works, and my question is more about the design of the Rails syntax, because I want to make sure I'm not missing the bigger picture here: why is the first one necessary? If we're establishing that a user can access a list of shows through an intermediate with a non standard name of saved_shows
, why also establish has_many :saved_shows
?
I'm guessing I'm not the first one to have hit a snag on this one, so I'm curious why Rails requires this seemingly redundant definition. Is it just a poorly chosen syntax or is there some deeper design behind it?