0
내 신청서에 다음과 같은 관계가 있습니다.제품 및 카테고리 관계
제품은 여러 카테고리, 하위 카테고리 및 하위 하위 카테고리에 속할 수 있습니다.
현재 디자인 : 특정 카테고리의
Product:
has_many :categorizations, dependent: :destroy
has_many :categories, through: :categorizations
has_many :sub_categories, through: :categorizations
has_many :sub_sub_categories, through: :categorizations
Category:
has_many :categorizations
has_many :products, through: :categorizations
has_many :sub_categories, class_name: 'Category', foreign_key: 'parent_id'
belongs_to :parent_category, class_name: 'Category', foreign_key: 'parent_id'
Categorization:
belongs_to :category
belongs_to :sub_category, class_name: 'Category', foreign_key: 'sub_category_id'
belongs_to :sub_sub_category, class_name: 'Category', foreign_key: 'sub_sub_category_id'
belongs_to :product
제품은 category.products
로 표시 할 수 있습니다.
특정 제품 sub_category
및 sub_sub_category
에 액세스하는 방법은 무엇입니까?
내가 변경해야 할 사항은 무엇입니까 ??
당신을 감사 테이블에
parent_id
추가 .. 그리고 디자인 위에 미세 또는 자기 참조 관계를 사용하고 'sub_category' 대신'category'에있는 것이 더 낫습니다. – rAzOr내 편집 된 답변보기 @rAzOr – fongfan999