db中的购物车 - 订单行表或单独的购物车表?(Shopping cart in db - order lines table or separate cart table?)

我想将多租户应用的购物车数据存储在数据库中。

我想知道最好是否有一个单独的表(我工作的项目是这样做但我认为他们从会话迁移到该解决方案)或者我是否应该将所有内容放在订单行表中并具有订单状态决定它是购物车还是订单的一部分。

每种解决方案的优缺点是什么?

I want to store the cart data of my multitenant app in the database.

I am wondering if it would be better to have a separate table (a project I work on does it that way but I think they migrated from sessions to that solution) or if I should put everything in the order lines table and have an order status to decide if its part of a cart or an order.

What would be the pros and cons for each solution?

最满意答案

如果在您的系统中,与购物车相关的数据与订单行完全相同且只是状态不同,那么您可以将所有数据保存在同一个表中,并将外键的值与状态表区分开来。

但是,与下订单和购物车产品相关的属性通常不同。 购物车相关数据基本上保持用户恢复其活动的状态,并且可能呈现可能被消费的产品(有点不寻常)。 另一方面,与订单行相关的数据很重要,它们与交易,财务信息,股票,历史,趋势等相关联,这是实际重要的数据。

因此,下订单是具有价值的数据,可以进行分析和处理,而购物车只是为了方便用户而存储。 通常,最好将它们分开以保持灵活性和可扩展性

If, within your system, the data related to the cart are exactly the same as the order line and only differ by a status, then you could keep all in the same table and differentiate by the value of the foreign key to a status table.

However the properties related to placed orders and products of a cart usually differ. The cart related data basically hold a state for a user to resume her activities and possibly present products that are likely to be consumed (a bit unusual). On the other hand data related to order lines are important, they are connected with transactions, financial info, stock, history,trends etc, this is the data that actually matters.

So the placed orders are the data with value, that get analysed and processed, while the cart is only stored for user's convenience. Generally it is best to keep them separated for flexibility and scalability.

更多推荐