I Have this setup:
Continent -> Country -> City -> Post
and I Have
class Continent < ActiveRecord::Base
has_many :countries
end
class Country < ActiveRecord::Base
belongs_to :continent
has_many :cities
end
class City < ActiveRecord::Base
belongs_to :country
has_many :posts
end
class Post < ActiveRecord::Base
belongs_to :city
end
How do I get all the Continents having posts trough this associations
Like:
@posts = Post.all
@posts.continents #=> [{:id=>1,:name=>"America"},{...}]
You can do this:
Or this:
Or this:
Or this: