RoR associations through or not through?
- by showFocus
I have four models that are related to one another, the way I have it setup at the moment is I have to select a county, region and country when entering a new city.
class Country < ActiveRecord::Base
has_many :regions
has_many :counties
has_many :cities
end
class Region < ActiveRecord::Base
has_one :country
has_many :counties
has_many :cities
end
class County < ActiveRecord::Base
has_one :country
has_one :region
has_many :cities
end
class City < ActiveRecord::Base
has_one :country
has_one :region
has_one :county
end
Would it be better to use the :through symbol in the association? So I could say the city:
has_one :country, :through => :region
Not sure if this is correct, I have read how :through works but I'm not sure if this is the best solution.
I am a newbie and while I'm not struggling with the syntax and how things work, it would be good to get opinions on best practices and the way things should be done from some rails wizards!
Thanks in advance.