Hey, I have an association chain like this: Site has_many Feed(s) has_many FeedEntry(/ies) has_many Articles where the reverse is always belongs_to: Article belongs_to FeedEntry belongs_to Feed belongs_to Site Now what I want is to get all articles that belong to a specific Site, something like Site.first.articles I can''t figure out how to do this, or if it''s possible with has_many :through Can anyone give me a hint please? Thank you --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
you can use through na.. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
sorry, what? On Feb 25, 1:55 pm, Priya Buvan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> you can use through na.. > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
On Wed, Feb 25, 2009 at 5:27 AM, sol <ch.blank-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > sorry, what? > > On Feb 25, 1:55 pm, Priya Buvan <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > you can use through na.. >Hi, I recommend reading AWDwR 3ed on using ''has_many through'' for the details. Good luck, -Conrad> > > -- > > Posted viahttp://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, On Feb 25, 2:34 pm, Conrad Taylor <conra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, I recommend reading AWDwR 3ed on using ''has_many through'' for the > details.These details are the reason I''m asking :) is this: http://agilewebdevelopment.com/plugins/nested_has_many_through still the only way to do this? or am I just blind. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
perhaps the responses could be a bit more helpful here? sol, I have done it through 2 level associations using through eg. Sites has_many :feed_entries, :through=>:feeds I have tried with 3 levels, but never got it to work, ie, how do you chain the throughs. I have tried to make sure that the through is in place at each level, but to no avail. Perhaps someone may be able to enlighten us. Tonypm --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I don''t know if you can get there just w/HM=>T, but you can fake out the last link w/a custom method. This is working for me: class Article < ActiveRecord::Base belongs_to :feed_entry end class FeedEntry < ActiveRecord::Base belongs_to :feed has_many :articles end class Feed < ActiveRecord::Base belongs_to :site has_many :feed_entries has_many :articles, :through => :feed_entries end class Site < ActiveRecord::Base has_many :feeds def articles arts = [] self.feeds.each do |f| arts << f.articles end # Not sure if that uniq call is necessary... arts.flatten.uniq end end That gives me a my_site.articles collection which returns the union of all articles attached to any feed_entry attached to any feed attached to the Site. HTH, -Roy -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk@googlegroups.com] On Behalf Of sol Sent: Wednesday, February 25, 2009 2:11 AM To: Ruby on Rails: Talk Subject: [Rails] Association through 2 intermediate Models Hey, I have an association chain like this: Site has_many Feed(s) has_many FeedEntry(/ies) has_many Articles where the reverse is always belongs_to: Article belongs_to FeedEntry belongs_to Feed belongs_to Site Now what I want is to get all articles that belong to a specific Site, something like Site.first.articles I can''t figure out how to do this, or if it''s possible with has_many :through Can anyone give me a hint please? Thank you --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---