Forum: Ruby on Rails Using through with habtm

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Serengeti (Guest)
on 2007-06-22 06:51
(Received via mailing list)
I have two models with an habtm relationship:

Foo has_and_belongs_to_many Bars (and vice-versa, obviously).

Let's say Bar has_many Bazs (how the heck do you pluralize Baz?).

It would be nice to be able to say that Foo has_many Bazs through =>
Bar, but this does not seem to work.

Am I right, or should it be possible to do this?

The best I have been able to do is this:

    bazs = []
    my_foo.bars.each do |b|
      bazs += b.bazs

That's not TOO messy, but not as clean as foo.bazs.

If I am right about foo.bazs not being possible, is there a better/
cleaner workaround than the one I am using?
This topic is locked and can not be replied to.