首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Rails建模帮助、关联和逻辑

Rails建模帮助、关联和逻辑
EN

Stack Overflow用户
提问于 2016-01-21 15:56:40
回答 1查看 61关注 0票数 0

我是一个初级开发人员,他刚刚完成了第一个rails项目。我面临着很多障碍,但从实践中学到了很多。到目前为止,我已经能够找出设计,设计中的多个用户以及所有这些好东西。但对授权很有信心。我仍然在学习,我相信我会找到答案的。

但在过去一周里,我所拥有的唯一一个砖墙时刻就是为订购部分建模我的应用。下面是我正在开发的应用程序的一个小摘要:

  1. Its B2B
  2. 用户类型为零售商和供应商。
  3. 零售商向供应商下订单
  4. 只有3种或3种以上的产品,product_type1,product_type2,product_type3
  5. 供应商每天更新产品类型的价格,零售商在仪表板上看到当前价格。
  6. 供应商也为每个零售商的每个产品的价格公式。

例如,他的底价+保证金,每个零售商的保证金是不同的。

那我该怎么做呢?我希望零售商向供应商下订单,并注明各自的价格。

我需要什么?

产品模型?价格和类型?

单独的公式模型?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-21 16:27:51

我理解你的感受,因为我以前确实有过这个问题,让我分享一下我所做的,希望它能帮助解决你的问题:

User模型:

代码语言:javascript
复制
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
end

Order模型:

代码语言:javascript
复制
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
end

Product模型:

代码语言:javascript
复制
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]
end

ProductCapture模型:

代码语言:javascript
复制
class ProductCapture < ActiveRecord::Base
  belongs_to :product
  attr_accessible :base_price, :margin

  def price
    price + margin
  end
end

....other models

所以我的想法是:

  1. 用户可能有许多零售商或供应商(验证这方面的要求,我不确定这是否正确,在您的情况下)
  2. 我们始终为零售商和供应商提供最新的产品捕获订单,确保使用最新的价格。
  3. 当零售商更新价格(基价+保证金)时,我们创建了一个新的ProductCapture,成为最新的一个,所有旧的捕获仍然在数据库中,因为旧订单仍然在使用它。
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34928360

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档