Many to Many and Related Records

I am working on a development which has a number of many to many
relationships using link tables. I would like to find a way of finding
related records which share common attributes.

For example, a User has many Regions and an Event has many Regions.

My question is, what is the simplest way to link Users directly to the
Events that have Regions in common with them. The model files
contain…

Class User…

has_many :user_regions
has_many :regions, :through => :user_regions

Class Event…

has_many :event_regions
has_many :regions, :through => :event_regions

Class Region…

has_many :user_regions
has_many :users, :through => :user_regions
has_many :event_regions
has_many :events, :through => :event_regions

All suggestions appreciated. Thanks.

Dan

On 15 January 2011 01:37, DanC [email protected] wrote:

I am working on a development which has a number of many to many
relationships using link tables. I would like to find a way of finding
related records which share common attributes.

For example, a User has many Regions and an Event has many Regions.

My question is, what is the simplest way to link Users directly to the
Events that have Regions in common with them. The model files
contain…

Have a look at the nested_has_many_through plugin.

Colin

Hi Colin,

Thank you, that did the trick.

Exactly what I wanted,

Dan