has_many through-속성 액세스

Ancinek

Offer라는 모델이 있습니다.

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_items에 액세스하려는 경우 Offer.first.offer_items오류가 발생합니다.

ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the association :section in model Offer

또한 OfferItem.attribute_names모든 속성 반환하지만 offer_id다른 속성 이 작동하지 않는 것처럼 보입니다. 여기서 무슨 일이 일어나고 있습니까?

SteveTurczyn

아니에요

has_many :offer_items, through: :section

이것의

has_many :offer_items, through: :sections

당신은 :section연관성 이없고 :sections연관성이 있습니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

연결에서 조인 테이블 속성 (has_many : through)에 액세스하는 방법

분류에서Dev

ActiveAdmin 필터 : has_many : through 속성

분류에서Dev

액세스 조인 테이블 속성을 통한 has_many 양식

분류에서Dev

중첩 된 속성에 대한 양식 도우미 has_many through in rails 4

분류에서Dev

has_many 후 has_many : through?

분류에서Dev

Rails 4 활성 레코드 모델 has_many through associations?

분류에서Dev

has_many : through in Rails로 생성 및 업데이트

분류에서Dev

활성 레코드 연결-오류 w has_many : through Association?

분류에서Dev

has_many : through를 사용하여 현재 객체에 속하지 않는 중첩 된 속성

분류에서Dev

link to relationship name in has_many :through

분류에서Dev

has_many : through 양식

분류에서Dev

Rails has_many : through with the where 절

분류에서Dev

Finding Users with has_many :through

분류에서Dev

Make has_many :through not deleteable

분류에서Dev

Join has_many :through attributes

분류에서Dev

has_many / : through rails4

분류에서Dev

Rails has_many : through, undefined method

분류에서Dev

has_one : through 및 has_many : through

분류에서Dev

Rails : has_many : through 연관에있는 조인 테이블의 여러 새 레코드에 속성 값 추가

분류에서Dev

Rails는 has_many : through 관계에서 데이터를 생성합니다.

분류에서Dev

Rails는`has_many : through` 텍스트 필드를 통해 검색합니다.

분류에서Dev

Rails has_many 중첩 속성 + paperclip gem

분류에서Dev

Has many를 통해 속성에 액세스 할 수 없습니다.

분류에서Dev

속성 액세스

분류에서Dev

Can a has_many :through association have other associations?

분류에서Dev

Rails 3: has_many through controller action

분류에서Dev

Creating multiple has_many :through records with form_for

분류에서Dev

has_many : through로 사용자 찾기

분류에서Dev

NoMethodError: undefined method `user' for has_many :through Association

Related 관련 기사

  1. 1

    연결에서 조인 테이블 속성 (has_many : through)에 액세스하는 방법

  2. 2

    ActiveAdmin 필터 : has_many : through 속성

  3. 3

    액세스 조인 테이블 속성을 통한 has_many 양식

  4. 4

    중첩 된 속성에 대한 양식 도우미 has_many through in rails 4

  5. 5

    has_many 후 has_many : through?

  6. 6

    Rails 4 활성 레코드 모델 has_many through associations?

  7. 7

    has_many : through in Rails로 생성 및 업데이트

  8. 8

    활성 레코드 연결-오류 w has_many : through Association?

  9. 9

    has_many : through를 사용하여 현재 객체에 속하지 않는 중첩 된 속성

  10. 10

    link to relationship name in has_many :through

  11. 11

    has_many : through 양식

  12. 12

    Rails has_many : through with the where 절

  13. 13

    Finding Users with has_many :through

  14. 14

    Make has_many :through not deleteable

  15. 15

    Join has_many :through attributes

  16. 16

    has_many / : through rails4

  17. 17

    Rails has_many : through, undefined method

  18. 18

    has_one : through 및 has_many : through

  19. 19

    Rails : has_many : through 연관에있는 조인 테이블의 여러 새 레코드에 속성 값 추가

  20. 20

    Rails는 has_many : through 관계에서 데이터를 생성합니다.

  21. 21

    Rails는`has_many : through` 텍스트 필드를 통해 검색합니다.

  22. 22

    Rails has_many 중첩 속성 + paperclip gem

  23. 23

    Has many를 통해 속성에 액세스 할 수 없습니다.

  24. 24

    속성 액세스

  25. 25

    Can a has_many :through association have other associations?

  26. 26

    Rails 3: has_many through controller action

  27. 27

    Creating multiple has_many :through records with form_for

  28. 28

    has_many : through로 사용자 찾기

  29. 29

    NoMethodError: undefined method `user' for has_many :through Association

뜨겁다태그

보관