Hello,
I have 4 tables Provinces, Districts, Cities and Municipalities.
A Province has many Districts. A district has many Cities, and a City has
many Municipalities.
With this code :
class Province < ActiveRecord::Base
# relationship
has_many :districts
has_many :cities, :through => :districts
end
I can do this :
@province = Province.find(:first)
@province.cities.first.name
I would like to go one step further and be able to do
@province.districts.first.name
Is it possible?
How can I do that?
Thanks for sharing your experience.
Thomas.
Unless there's a typo in your code somewhere, I don't think there's any
reason that you shouldn't be able to do that now, with what you've
already got.