You can do it:
Continent.all(:joins => {:countries => {:cities => :posts}}).uniq
Or that:
class Continent < ActiveRecord::Base
has_many :countries
named_scope :with_post, :joins => {:countries => {:cities => :posts}}
end
Continent.with_post.uniq
Or that:
Post.all(:include => {:city => {:country => :continent}}).map { |post| post.city.country.continent }.uniq
Or that:
class Post < ActiveRecord::Base
belongs_to :city
named_scope :include_continent, :include => {:city => {:country => :continent}}
def continent
city.try(:country).try(:continent)
end
end
Post.include_continent.map(&:continent).uniq
source
share