레일 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 메소드를 작성할 수 있지만 user에 대해 has_many freq_bands를 가질 수 있는지 알고 싶습니다. 이 방법으로 나는 전화를 연결할 수 있습니다. 내가하고 싶은 무엇
내가 그것을 내가 좋아하는 것, 가능하면 다른 플러그인을 사용하지 않도록이 플러그인 그러나 http://github.com/ianwhite/nested_has_many_through
를 사용하여 중첩 된 has_many을 가질 수 있습니다 생각하고 전적으로 의존
class User < ActiveRecor::Base
has_many :frequence_bands, :through => phones
end
입니다 울타리.
레일은 이것을 이미하지 않았습니까? 그것은 당신이 묘사 한 것과 똑같이 작동합니다. 'has_many : frequency_bands, : through => : phones'. – jamuraa