【发布时间】:2018-12-07 01:33:20
【问题描述】:
我需要设计包含产品数据的表格结构以满足以下要求:
1. A product consists of the following fields: EAN, CN, description, pvp
2. There are several types of users that access the products. The user types are not stable, they can be added or deleted at any time.
3. Any of the fields of the products may vary depending on the type of user who views it. For example:
我们有三个用户:
1 - John - guest
2 - David - client
3 - Vicent - vip
默认情况下,我们有此数据的产品:
8470001234567 - 123456 - Iphone X - $799
访客用户看不到此数据,请参阅以下内容:
8431239876547 - 987654 - Iphone X - $849
client用户默认看到数据,vip用户看到:
8470001234567 - 654321 - Iphone X Sale - $709
这意味着用户会看到给定产品的默认数据,除非其类型存在异常。该异常可以影响任何字段(id 除外)。
我能想到这个结构:
- 产品:id、ean、cn、描述、pvp
- PRODUCT_EXCEPTION:product_id、user_type_id、ean、cn、description、pvp
我已经验证了使用这种结构会进行很多查询,您是否想到了一种方法来优化它,以便不必进行这么多查询?
注意 1:产品包含在具有一定数量产品的报价中。 注 2:我使用 Laravel。 Offer模型与产品有关系,即我通过以下方式获取产品:$offer->products()
【问题讨论】:
标签: laravel laravel-5 database-design class-design