2013-10-10 67 views
0

我有2種型號:如何在Rails 3中創建複雜的有很多關係?

Location 
+ id 
+ woeid 

TownKeyTowns 
+ id 
+ town_woeid 
+ key_town_woeid 

而且關係是這樣:

1地點有1個key_town_woeid,這是通過town_woeid訪問。

town_woeid和key_town_woeid都是直接使用位置表中的woeid列的位置。

我想可以說,例如:

Location.key_town

到目前爲止,我有以下幾點:

town_city = TownKeyTown.where(:town_woeid => Location.woeid).first 
key_city = Location.find(town_city.key_town_woeid) 

幫助!

謝謝!

回答