# Complex association

**URL:** <https://www.ruby-forum.com/t/complex-association/191390>\
**Category:** Rails\
**Created:** [July 11, 2010, 4:57pm UTC](https://www.ruby-forum.com/t/complex-association/191390 "2010-07-11T16:57:55Z")\
**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:** [July 11, 2010, 4:57pm UTC](https://www.ruby-forum.com/t/complex-association/191390/1 "2010-07-11T16:57:55Z")

</div>

Hello,  
I am working with 3 models: user, band, event.

- A user has many bands and a bands has many users.
- An event has one band, and a band has many events.

the association I am trying to do is between users ands events.

I tried has many through but the is not working because the foreign key  
is not the the table but in an association table.

How could I do this?

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:** [July 12, 2010, 12:56pm UTC](https://www.ruby-forum.com/t/complex-association/191390/2 "2010-07-12T12:56:30Z")

</div>

You mean you want to get all the events associated with a user’s bands?

try

User  
has\_many :events, :through =\> :bands

I just tested this with an equivalent pair of associations and it worked  
fine. Although this will work as a ‘get’ association i’m not sure if it  
will work as a way of adding events to users, since you’d need to  
provide details of the joining band. You should beware of triangular  
association sets like this anyway.
