Nested has_many

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 frequencies_bent for the user. I know that I can write a def freq_bands method for a User, but I would like to know if it is possible to have has_many freq_bands for a User. That way I can bind 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 use the nested has_many with 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 the rails.

+3
source share
2 answers
class User < ActiveRecord::Base
  has_many :phones
  has_many :frequence_bands, :through => :phones
end

. has_many_through, has_many_through, .

(: ":" )

+7

3 nested_has_many_through gem, 3.1 , , . ( .)

0

Source: https://habr.com/ru/post/1738340/


All Articles