Using through with habtm

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
end
bazs.uniq!

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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs