我有四個模型是相互關聯的,我現在設置的方式是我必須在進入一個新城市時選擇一個縣,地區和國家。通過或不通過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