我有四个模型是相互关联的,我现在设置的方式是我必须在进入一个新城市时选择一个县,地区和国家。通过或不通过RoR协会?
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
在关联中使用:through
符号会更好吗?所以我可以说这个城市:
has_one :country, :through => :region
不知道这是正确的,我已经阅读如何:通过作品,但我不知道这是否是最好的解决办法。
我是一名新手,虽然我没有为语法和事情如何工作而苦苦挣扎,但最好从最佳实践中获得意见,并从某些导轨向导中完成某些事情。
在此先感谢。
谢谢,威尔,我过于复杂。 – showFocus 2010-04-08 02:58:10