Complex association

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 :slight_smile:

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.