ランニングレール3.2.1。ドキュメント(http://guides.rubyonrails.org/association_basics.html#the-has_many-through-association)に示されているように、関連付けによって単純なネストされたhas_manyを試してみます。
class Company < ActiveRecord::Base
has_many :locations, :dependent => :destroy
has_many :assets, :through => :locations
has_many :components, :through => :assets
end
class Location < ActiveRecord::Base
belongs_to :company
has_many :assets
has_many :components, :through => :assets
end
class Asset < ActiveRecord::Base
belongs_to :location
has_many :components
end
class Component < ActiveRecord::Base
belongs_to :asset
end
コンソールでCompany.find(2)
は、同様に正常に動作しますが、またはCompany.find(2).locations
ではありません。私は得る:Company.find(2).assets
Company.find(2).components
1.9.3p0 :071 > Company.find(2).assets
Company Load (0.8ms) SELECT "companies".* FROM "companies" WHERE "companies"."id" = $1 ORDER BY name ASC LIMIT 1 [["id", 2]]
NoMethodError: undefined method `assets' for #<Company:0x007f939d714318>
ここで何かが足りないようです。私はもう1レベル深くネストされていますが、ドキュメントによると、これは問題ないはずです。