0
Listings
을 통해 조인 된 Sequel::Model
항목 및 상점이 있으면 Items
및 해당하는 Stores
이 목록의 특성을 기반으로하고 싶습니다. 내가 잘 모르겠어요이 (아래 그림 참조)하지만, (A)을 할 .association_join
과 .where
절을 사용할 수있어조인 테이블의 특성을 기반으로 연관된 후속 모델에 대한 쿼리
DB.create_table? :items
primary_key :id
end
DB.create_table? :stores
primary_key :id
end
DB.create_table? :listings
foreign_key :store_id
foreign_key :item_id
TrueClass :active, null: true
String :name
end
class Item < Sequel::Model
many_to_many :stores, join_table: :listings
end
class Store < Sequel::Model
many_to_many :items, join_table: :listings
end
class Listing < Sequel::Model
end
이 올바른 경우는 (B는) 그것은 모두의 소품 결과를 산출 (C) Item
결과에 #stores
을 호출하면 다른 쿼리가 실행됩니다.
Item.association_join(:stores).where(active: true, name: 'Sears').eager(:stores).first()
내 최종 목표는 열심히 #stores
를로드 Item
의의 데이터 세트입니다.
어떻게하면 좋을까요? 감사!