Design Element
Comment on "Association Join Models in Rails"
by Scott Stevenson — Dec 30
the typical use for such a join table is to implement a many-to-many relationship. Since Core Data natively supports to-one and to-many relationships, and also handles inverse management automatically

I'm still new at Rails concepts, but I'm not sure this really covers the whole picture. Rails natively supports many-to-many inverse relationships. In the O'Reilly book they use the example of photos and categories:

has_and_belongs_to_many :photos has_and_belongs_to_many :categories

Which allows you you do things like this: << new_photo photo.categories << new_category

The join table is handled transparently, just as in Core Data (other than the fact that you have to create the migration).

In the same book, the association join models come into play when the Slideshow, Slide, and Photo classes are used together. A Slide has a belongs_to relationship to both Slideshow and Photo.

A Slide is more than just a simple join because it maintains information about a Photo which is specific to a Slideshow. In other words, the Slide could maintain a caption but have its Photo reference change. An association from Slideshow to Photo using :through is just a convenience.

The example on this page gives a better example. Let me know if you still think the original point is valid. I'd be curious to know if I'm missing something about Rails here.
Back to "Association Join Models in Rails"
Design Element

Copyright © Scott Stevenson 2004-2015