nested has_many

Posted by dorelal on Stack Overflow See other posts from Stack Overflow or by dorelal
Published on 2010-03-24T14:16:41Z Indexed on 2010/03/24 14:43 UTC
Read the original article Hit count: 83

Filed under:

I am using Rails 2.3.5.

Class User < ActiveRecord::Base
  has_many :phones
end

class Phone < ActiveRecord::Base
  has_many :frequency_bands
end

I want to get all the frequency_bands for a user. I know I can write a method def freq_bands for User but I would like to know if it is possible to have has_many freq_bands for a User. In this way I can chain the call.

What I would like to have is

class User < ActiveRecor::Base
   has_many :frequence_bands, :through => phones
end

I think it is possible to have nested has_many using this plugin http://github.com/ianwhite/nested_has_many_through

However if possible I would like to avoid using another plugin and rely solely on rails.

© Stack Overflow or respective owner

Related posts about ruby-on-rails