# Has\_many ... through Association

**URL:** <https://www.ruby-forum.com/t/has-many-through-association/187008>\
**Category:** Rails\
**Created:** [April 15, 2010, 4:58pm UTC](https://www.ruby-forum.com/t/has-many-through-association/187008 "2010-04-15T16:58:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc79bd/32.png) [@gregm](https://www.ruby-forum.com/u/gregm)\
**Post date:** [April 15, 2010, 4:58pm UTC](https://www.ruby-forum.com/t/has-many-through-association/187008/1 "2010-04-15T16:58:09Z")

</div>

Hi,

Let’s say I have 4 models: City, Line, Direction, Message  
City ha many lines  
lines has many directions  
and direction has many message

Tell me if what’s next is correct  
Line as many messages through line  
City has many messages throufh line

Is this possible especially for the city model? Is this the correct way  
to access messages from city?

Greg

---

<div class="post-metadata">

**Author:** ![gregm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc79bd/32.png) [@gregm](https://www.ruby-forum.com/u/gregm)\
**Post date:** [April 15, 2010, 5:49pm UTC](https://www.ruby-forum.com/t/has-many-through-association/187008/2 "2010-04-15T17:49:35Z")

</div>

> Tell me if what’s next is correct  
> Line as many messages through line  
> No  
> City has many messages throufh line  
> No

City ha many lines  
Line has many directions  
Direction has many messages  
+  
City has many directions through lines  
City has many messages through directions

This will allow you to do access a city’s messages directly with  
city.messages.

For this you would need the “nested has many through” gem, as rails  
cannot use “has many through” more than one level deep.

> **[GitHub - ianwhite/nested\_has\_many\_through: rails plugin that allows has\_many...](https://github.com/ianwhite/nested_has_many_through)**
>
> rails plugin that allows has\_many :through to go through other has\_many :throughs - GitHub - ianwhite/nested\_has\_many\_through: rails plugin that allows has\_many :through to go through other has\_man...
