我正在使用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