I have a relationship in which a post belongs to the city which inturn belongs to a state like:
class Post < ActiveRecord::Base
belongs_to :city
end
class City < ActiveRecord::Base
belongs_to :state
end
Now i want to find all the posts along with the their cities and the states to which the belong to. I wrote the following query to fetch the posts with their cities but out of ideas on how to fetch the corresponding state with the city in the same finder:
@post = Post.find :all, :include => [:city]
Any help is appreciated.
Thanks.
Post.all( :include => { :city => :state })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With