设计三个实体之间的许多关系 [英] Designing many to many relationship between three entities

查看:329
本文介绍了设计三个实体之间的许多关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法对这种情况进行建模。
我正在设计一个基于位置的优惠券系统。用户可以定义区域和优惠,然后将每个优惠关联到多个区域。每个区域也可以有多个优惠。所以区和报价有很多关系。用户实体拥有两个实体。区域和报价只能在相同的用户拥有这两者的情况下相关联。
图可以非常有帮助。
谢谢。

解决方案

假设用户可以拥有自己的区域和独立于区域和优惠是否实际连接的提议,您可以做这样的事情:





这是一个钻石形依赖关系的经典问题,钻石底部必须引用相同的 钻石,通过使用识别关系来确保,所以顶部的PK是双面传播的,然后合并在底部(注意FK1和FK2在前面的ZONE_OFFER.USER_ID)。



如果有外部原因,您可以随时向此模型添加更多(代理?)键,但这种基本结构必须存在于某些形状或形式,以确保只能连接相同用户的区域和优惠。


I'm having trouble modelling this situation. I'm designing a location-based coupon system. A user can define zones and offers and then associate each offer to multiple zones. Also each zone can have more than one offer. So zone and offer have a many to many relationship. The user entity owns both entities. A zone and an offer can only be associated if the same user owns both of them. A diagram can be very helpful. Thanks.

解决方案

Assuming a user can own own zones and offers independently from whether zones and offers are actually connected, you can do something like this:

This is a classic problem of diamond-shaped dependency where the diamond bottom must reference the same diamond top for both diamond sides, which is ensured by using identifying relationships so the top PK is propagated down both sides and then merged at the bottom (note FK1 and FK2 in front of ZONE_OFFER.USER_ID).

You can always add more (surrogate?) keys to this model if there are external reasons to do so, but this basic structure must exist in some shape or form to ensure only zones and offers of the same user can be connected.

这篇关于设计三个实体之间的许多关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆