Chris Mear wrote:
> The has_and_belongs_to_many assumes that the join table doesn't have a
> column called 'id' -- you'll see that the SQL it generates just
> SELECTs an 'id' column, so it's (erroneously) picking up the one from
> the join table in your situation.
>
> If your join table is really a fully-fledged model of its own, then
> you need to bring it into the association explicitly, and use the
> :through option to connect media and tour_locations:
...
Thanks! This was exactly what I needed to know.
Further, it greatly simplified my access to subsets of the has_many
:media relationship:
has_many :images,
:through => :media_tour_locations,
:source => :medium,
:conditions => "media_type = 'image'",
:order => 'media_tour_locations.medium_sequence'
... whereby I can use aTourLocation.images and get the images back in
the sequence specified for that relationship.
I _am_ relying on the :order option to produce a correct ORDER BY
clause. For Rails 2.3.5 and sqlite3 3.6.12, the generated SQL looks
right, and I get the expected results.
Will this hold up with different versions and back ends, or am I relying
on an implementation detail?
— F
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.