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.
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.