Посмотрите полиморфные ассоциации, если вы определенно хотите сохранить все это в LineItems.Тогда сделайте LineItems поли для продуктов, квартиры и автомобиля.Но я думаю, что у вас плохой дизайн.Покупка и аренда очень разные.При аренде у вас будет продолжительность, единый адрес или регистрация, которая не должна быть забронирована дважды.Вернитесь и работайте над ERD.
Один из вариантов лучшего дизайна:
NB Я изменил LineItem на CartItem для ясности.
class Products
has_many :cart_items
has_many :order_items
attributes :name, :price, :content
end
class Cart
has_many :line_items
end
class CartItem
belongs_to :products
belongs_to :carts
end
class CartRental
# :cart_rentable_type, :cart_rentable_id would be the fields for the polymorphic part
belongs_to :cart_rentable, :polymorphic => true
belongs_to :carts
attributes :from, :till
end
class Order
attr :buyer_details, :pay_type
end
class OrderItem
belongs_to :products
belongs_to :order
end
class Rental
belongs_to :rentable, :polymorphic => true
belongs_to :order
# :rentable_type, :rentable_id would be the fields for the polymorphic part
attributes :from, :till, :status
end
class Car
attributes :name, :car_type, :color
has_many :cart_rentals, :as => :cart_rentable
has_many :rentals, :as => :rentable
end
class Apartment
attributes :name, :size, :location
has_many :cart_rentals, :as => :cart_rentable
has_many :rentals, :as => :rentable
end