# Deep has\_many through

**URL:** <https://www.ruby-forum.com/t/deep-has-many-through/157081>\
**Category:** Rails\
**Created:** [January 7, 2009, 8:16am UTC](https://www.ruby-forum.com/t/deep-has-many-through/157081 "2009-01-07T08:16:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramontayag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c6cbf5/32.png) [@ramontayag](https://www.ruby-forum.com/u/ramontayag)\
**Post date:** [January 7, 2009, 8:16am UTC](https://www.ruby-forum.com/t/deep-has-many-through/157081/1 "2009-01-07T08:16:09Z")

</div>

Hey everyone,

I tried searching for this and asking in #rubyonrails but got no answer.

Given:  
class Aye; has\_many :bee; end  
class Bee; has\_many :cees; end  
class Cee; has\_many :dees end

Is this possible?:  
aye.dees

I know how that with has\_many through you can get aye.cees but can it  
go further than that?

While searching I came accross  
[http://wiki.rubyonrails.org/rails/pages/ThroughAssociations](http://wiki.rubyonrails.org/rails/pages/ThroughAssociations) that  
talked about it (but this was a wish):  
class Manufacturer

# using an array specifies the order in which the relationships occur.

has\_many :review\_comments, :through =\> [:products, :reviews]

# For that matter, we should be able to string together as many

relationships as we like.

# For example, for intergalactic commerce, we might want to find out

which moons are associated with a given manufacturer.  
has\_many :moons, :through =\> [:distributors, :space\_stations,  
:planets, :moons]  
end

Thanks,  
Ramon T.

---

<div class="post-metadata">

**Author:** ![ramontayag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c6cbf5/32.png) [@ramontayag](https://www.ruby-forum.com/u/ramontayag)\
**Post date:** [January 7, 2009, 11:31am UTC](https://www.ruby-forum.com/t/deep-has-many-through/157081/2 "2009-01-07T11:31:22Z")

</div>

Hi,

you provide your own answer 🙂

class Aye  
has\_many :bees # plural !  
has\_many :cees, :through =\> :bees # this specifies which class is  
intermediary  
end  
class Bee  
has\_many :cees  
end  
class Cee  
has\_many :dees  
end

And then you can use Aye.dees.

Elise
