在线商店的数据库

时间:2013-07-26 06:36:02

标签: mysql ruby-on-rails database relational-database database-schema

我即将建立一个在线电子商务网站,用于销售鞋类,服装等产品。但我无法弄清楚如何设置架构(表和所有)。我在 Ruby on Rails 中使用 Mysql 进行此操作,而且我是ROR中的新手。

详情如下: -

我在产品中有不同的类别,例如鞋类,服装,配饰,手袋等分别为男士和女士< /强>

买方选择产品并将其添加到购物车并继续chekout。我们只有一个货到付款类型付款系统。我们不会创建任何用户帐户。没有用户帐户

我应该如何在Rails中实现所有控制器和模型?
我应该为每个类别
制作单独的表格吗? 我应该如何在男性和女性中对所需产品进行分类? 提供完整的架构和关系表 Rails方式。

2 个答案:

答案 0 :(得分:3)

您需要Categories表和Products表。在产品表格中,您需要category_id:integer字段。

<强> Category.rb

has_many :products

<强> Product.rb

belongs_to :category
has_many :line_items

<强> Cart.rb

has_many :line_items

LineItem.rb (表line_itemsproduct_id:integercart_id:integer

  belongs_to :cart
  belongs_to :product

每当有人向product添加cart时,它会创建line_itemproduct_idcart_id,您还可以添加数量字段进行更新如果客户订购更多相同类型的产品。

对于男性女性类型的产品,您可以在产品表格中添加一个字段,该字段将标识此产品适合他或她,for_men: boolean, default:true

<强> Product.rb

belongs_to :category
has_many :line_items

scope :men, -> {where(for_men: true)}
scope :women, -> {where(for_men: false)}

以及何时致电

 products = Product.all
 products.women

它只会显示标记为女性类型的产品,其中for_men字段为false

如果您按类别提取产品:

category = Category.find 1

category.products.women 

将向products women category显示{{1}}。

答案 1 :(得分:1)

电子商务商店所需的主要表格是。

    Product table
    Product type - type can define its type and category which it belongs to
    Cart - This table depends how you are dealing with cart items.
    Users - have an assosisation has many with oder
    Orders - have an assosiation with order status
    Order status
    Discount or Coupon Code
    Inquiry