# Model associations

**URL:** <https://www.ruby-forum.com/t/model-associations/154218>\
**Category:** Rails\
**Created:** [November 26, 2008, 2:47pm UTC](https://www.ruby-forum.com/t/model-associations/154218 "2008-11-26T14:47:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![adam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4af34b/32.png) [@adam](https://www.ruby-forum.com/u/adam)\
**Post date:** [November 26, 2008, 2:47pm UTC](https://www.ruby-forum.com/t/model-associations/154218/1 "2008-11-26T14:47:23Z")

</div>

I’ve got the folowing models associated with each other

venture \<— component --\> attribute --\> service

‘–\>’ means ‘belongs to’ in case someone wonders 😉

The thing is i want to show in the ‘show’ action for the venture  
components ordered by the service

like so  
@venture.services.each do |service|  
service.components.each do |component|  
= component.name  
= component.attribute.name

In the venture model I got how to have the attributes  
Venture (part)  
has\_many :attributes\_, :through=\>:components, :source=\>:attribute  
has\_many :components,:dependent=\>:destroy

Component  
belongs\_to :attribute

So its easy but the problem is with getting the services the way i  
want to  
It’s important for me to be able to do it in a simple way so I tried  
all sorts of combinations like

has\_many :services, :through=\>:attributes\_

Any ideas on this one? Is it possible this way through has\_many and  
belongs?

cheers
