我是一个初级开发人员,他刚刚完成了第一个rails项目。我面临着很多障碍,但从实践中学到了很多。到目前为止,我已经能够找出设计,设计中的多个用户以及所有这些好东西。但对授权很有信心。我仍然在学习,我相信我会找到答案的。
但在过去一周里,我所拥有的唯一一个砖墙时刻就是为订购部分建模我的应用。下面是我正在开发的应用程序的一个小摘要:
例如,他的底价+保证金,每个零售商的保证金是不同的。
那我该怎么做呢?我希望零售商向供应商下订单,并注明各自的价格。
我需要什么?
产品模型?价格和类型?
单独的公式模型?
发布于 2016-01-21 16:27:51
我理解你的感受,因为我以前确实有过这个问题,让我分享一下我所做的,希望它能帮助解决你的问题:
User模型:
class User < ActiveRecord::Base
# A user is a registered person in our system
# Maybe he has 1/many retailers or suppliers
has_many :retailers
has_many :suppliers
endOrder模型:
class Order < ActiveRecord::Base
# An order was placed for supplier by retailer
belongs_to :retailer
belongs_to :supplier
# An order may have so many products, we use product_capture
# because the product price will be changed frequently
# product_capture is the product with captured price
# at the moment an order was placed
has_many :product_captures
endProduct模型:
class Product < ActiveRecord::Base
belongs_to :retailer
has_many :product_captures
# Custom type for the product which is not in type 1, 2, 3
enum types: [:type_1, :type_2, :type_3, :custom]
endProductCapture模型:
class ProductCapture < ActiveRecord::Base
belongs_to :product
attr_accessible :base_price, :margin
def price
price + margin
end
end....other models
所以我的想法是:
ProductCapture,成为最新的一个,所有旧的捕获仍然在数据库中,因为旧订单仍然在使用它。https://stackoverflow.com/questions/34928360
复制相似问题