[英]What is the right approach for storing different types of product data
I'm creating an application that stores product data in a (now) relational database. 我正在创建一个将产品数据存储在(现在)关系数据库中的应用程序。 But a washing machine has different properties then a laptop fe. 但是洗衣机和笔记本电脑的特性不同。 They both are a type of product, with always a price, title, desc and image, but only laptops have a harddisk (mostly) 它们都是一种产品,总是带有价格,标题,描述和图像,但是只有笔记本电脑才有硬盘(大部分是)
So what to choose as a model? 那么,要选择什么作为模型呢?
I'm favouring option 3, but that still feels wrong and hard to scale and I'm unsure if I'm forgetting something or that my years of relational php / mysql thinking are steering me away from another and way better choice. 我赞成选项3,但是仍然感到错误且难以扩展,并且不确定是否遗忘了某些东西,或者我多年的关系php / mysql思考是否使我远离了另一个更好的选择。
Had the same dilemma. 有同样的困境。 Chose to go with one product database with essential information, another db with webshop information and then key value dbs for storing tags, and custom specifications which are shown on a seperate page (details page) 选择使用一个包含基本信息的产品数据库,另一个包含网店信息的数据库,然后选择用于存储标签和自定义规范的键值数据库,这些数据库显示在单独的页面(详细信息页面)上
Add location or category restrictions in combo with limits to keep the queries fast and look into cloud db hosting. 结合限制添加位置或类别限制,以保持查询的快速性并调查云数据库托管。
You need a kind of key/value tables to solve this relationally. 您需要一种键/值表来解决此关系。
But there are some things to consider. 但是有一些事情要考虑。 A washing machine may have 1200 or 1400 rpm but certainly not 367. So there are some values that must be picked from lists, whereas others my be free text. 洗衣机的转速可能为1200或1400 rpm,但肯定不是367。因此,有些值必须从列表中选取,而其他值则是自由文本。 Then there are probably values that are obligatory and others that are not, eg a computer that may come with a keyboard (which you could further specify) or not. 然后可能有一些强制性的值,而有些则不是,例如,可能带有键盘(您可以进一步指定)的计算机。
But let's say there are only value list properties (no free text) and for optional properties you have an entry 'none' in the list and for obligatory not. 但是,让我们说只有值列表属性(没有自由文本),对于可选属性,您在列表中有一个“无”条目,而没有必填项。 That means, however, that suddenly all properties of a category are "obligatory" (ie for a PC you must say what keyboard, even if it is 'none', whereas for a chair you must not ). 但是,这意味着类别的所有属性突然都是“必填”的(即,对于PC,即使不是键盘,您也必须说出什么键盘,而对于椅子,则必须不说 )。
This leads to something like: 这导致类似:
table category 表类别
category_id text c1 PC c2 Washing machine
table products 餐桌产品
product_id category_id text ... p1 c2 Washy WM1000 p2 c1 Super PC
table properties 表属性
property_id text 100 rpm 200 keyboard
table property_values 表property_values
value_id property_id text 21 100 1200 22 100 1400 23 200 with numpad 24 200 without numpad 25 200 none
category_properties category_properties
category_id property_id c1 200 c2 100
product_values product_values
product_id value_id p1 22 p2 23
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.