レコード モデルを使用して製品の重量を取得するにはどうすればよいですか? 私が知っているように、特定の記録のすべての製品を取得することは可能ですが、特定の製品の重量を取得する方法を見つけることができません.
class User < ActiveRecord::Base
has_many :eatings
end
class Eating < ActiveRecord::Base
belongs_to :user
has_many :records
end
class Record < ActiveRecord::Base
belongs_to :eating
end
class Product < ActiveRecord::Base
end
class WeightedProduct < ActiveRecord::Base
end
ユーザーが User.first.eatings.first.records.first.products.first.weight の 1 行で特定の製品の重量を取得できるようにするには、WeightedProduct を使用して Record モデルと Product モデルを作成する必要があります。