は私がオファーhas_manyのアクセスが、このようなデータベースを播種した後
class Offer < ApplicationRecord
has_many :sections
has_many :offer_items, through: :section
end
class Section < ApplicationRecord
belongs_to :offer
has_many :offer_items
end
class OfferItem < ApplicationRecord
belongs_to :section
belongs_to :offer
end
と呼ばれるモデルを持っている属性:
offer = Offer.create(name: "Offer A")
section = offer.sections.create(name: "Section A")
item = section.offer_items.create(name: "Item A")
項目が作成されていない私はOffer.first.offer_items
ようoffer_itemsにアクセスしたい場合は、それ
ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the association :section in model Offer
また、私はそれを見ることができますOfferItem.attribute_names
すべての属性を返しますが、offer_id
はありませんので、他のbelongs_toが機能していないようです。 ここでは何が起こっていますか?
これは前に尋ねられたと思います。この回答を確認してください。 http://stackoverflow.com/a/5120734/2891994 – Samuel
try: 'has_many:offer_items、through::sections'。 'through'値は別の関連付けと一致しなければなりません(エラーはそれをかなりうまく説明します) – Kkulikovskis