technology_id
다른 쿼리에서. 오류를 통해.질문:
Vendor.where(vendors: {company: nil}).joins(technologies_vendors: {technology_id: "Technology.select(:technology_id).where(url: 'ios',is_verified: true)"})
오류:
ActiveRecord::ConfigurationError: Association named 'technology_id' was not found on TechnologiesVendor; perhaps you misspelled it?
다음과 같은 관계로 설정된 세 가지 모델이 있다고 가정합니다.
Vendor has_many technologies_vendors
Technology has_many technologies_vendors
TechnologiesVendor belongs_to vendor
TechnologiesVendor belongs_to technology
귀하의 조건은 다음과 같습니다.
vendors should have 'nil' company
technologies should be verified and have 'ios' url
이 경우 원하는 것은 다음과 같습니다.
Vendor.
joins(technologies_vendors: :technology).
where({
vendors: {company: nil},
technologies: {url: 'ios', is_verified: true}
})
그러나이 merge
방법도 아주 쉽게 사용할 수 있습니다.
Vendor.
joins(technologies_vendors: :technology).
where(vendors: {company: nil}).
merge( Technology.where(technologies: {url: 'ios', is_verified: true}) )
그러나 두 경우 모두 두 번째 쿼리를 제거하거나 약간 수정해야합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다