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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 15 January 2011 01:37, DanC <d.m.colegate-VlwAjOFxKoqFxr2TtlUqVg@public.gmane.org> 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> > 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 > > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hi Colin, Thank you, that did the trick. Exactly what I wanted, Dan On Jan 15, 12:02 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 15 January 2011 01:37,DanC<d.m.coleg...-VlwAjOFxKoqFxr2TtlUqVg@public.gmane.org> 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 > > > > > 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 > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.