안녕하세요. 장바구니에 항목을 추가하는 데 문제가 있습니다. 레일 민첩한 책에서. 속성이 다른 제품 (아파트, 자동차)에 추가하려면다른 제품 유형의 장바구니에 상품 추가
class Products
has_many :line_items
attributes :name, :price, :content
end
class LineItem
belongs_to :products
belongs_to :carts
end
class Cart
has_many :line_items
end
class Car
attributes :name, :car_type, :color
end
class Apartment
attributes :name, :size, :location
end
class Order
attr :buyer_details, :pay_type
end
고객은 장바구니에 제품을 추가하고 e.x. 임대료 2 침실, 임대료를 내고 리무진을 지불하고 싶습니다. 장바구니에 추가하는 방법. lineitems에 apartment_id 및 car_id를 입력하면 오염됩니까? 올바른 접근 방식과 올바른 습관이 필요합니다. 모두에게 감사드립니다.
그건 내 질문입니다. 그것이 나쁜 디자인 인 경우, 그것을하는 올바른 방법은 무엇입니까? –
위의 답변이 당신을 위해 효과가있는 예제로 업데이트되었습니다. – TomDunning