I've only created a has_and_belongs_to_many association before and it is different from has_many :through. For a has_many :through association, do I need a join table? How does the actual association work? Do I need an index? I can't find a great tutorial on this, any suggestions?
Yes you need the join table. This shows how: http://railscasts.com/episodes/47-two-many-to-many
This may also be helpful; has_many :through questions
By the way if you need to search with condition this will help: Has many through associations with conditions
Also a great example with code of editing the nested attributes of the join table at Rails nested form with has_many :through, how to edit attributes of join model?.
All these are sorts of things you might find yourself wanting to do :)
Index are optional and also vary by db. mySQL used to only support 1 at a time. Not sure if that has changed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With