我正在使用Rails 2.3.5。嵌套has_many
Class User < ActiveRecord::Base
has_many :phones
end
class Phone < ActiveRecord::Base
has_many :frequency_bands
end
我想獲取用戶的所有frequency_bands。我知道我可以爲用戶編寫一個def freq_bands的方法,但我想知道是否可以爲用戶使用has_many freq_bands。通過這種方式,我可以連接電話。
我想吃點什麼是
class User < ActiveRecor::Base
has_many :frequence_bands, :through => phones
end
我認爲這是可能使用這個插件http://github.com/ianwhite/nested_has_many_through
但是,如果可能,我想避免使用其他插件有嵌套的has_many和單純依靠軌道。
不軌道已經這樣做了嗎?它與您所描述的完全一樣。 'has_many:frequency_bands,:through =>:phones'。 – jamuraa 2010-03-24 14:40:18