我正在尝试在 Rails 中创建销售点应用
现在我有一个项目模型。 items 模型包含商店中的每一种不同的商品。
现在我想创建一个订单模型。这个想法是这个模型将包含每个订单的项目及其数量。我将能够查看订单历史以生成分析等。
正确的做法是什么?
有很多:通过? Redis 设置? 其他想法?
最佳答案
典型的方法是使用 OrderLine 模型。这是您存储每件订购商品数量的地方。
class Order
has_many :order_lines
has_many :items, :through => :order_lines
end
class OrderLine
belongs_to :order
belongs_to :item
end
关于ruby-on-rails - Rails has_many :through,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7464429/