层次结构中的可选关系
我有一个层次结构区域 ->区域->其中区域是可选的扇区,即特定扇区可能属于区域,但用户可能不希望在区域级别分解。此外,扇区与区域不同,它们具有不同的属性,并且区域实际上是扇区的集合,
扇区还具有在层次结构中进一步相关的其他实体。
我想知道在数据库中对此进行建模的最佳方法是什么?我之前在类似的场景中做过此操作,并使用虚拟区域实体来允许存储扇区。
有人有更好的想法吗?
谢谢, 标记
I have a hierarchy Area -> Zone -> Sector where Zone is optional i.e. a particular Sector may belong to an Area but the user may not want to break down at the Zone level. Additionally Sectors are not the same as Zones, they have different properties and Zones are effectively a collection of Sectors
Sectors have other entities related further down the hierarchy as well.
What I'd like to know is what's the best approach to modelling this in a database? I've done this before in a similar scenario and used a dummy Zone entity to then allow storage of the Sectors.
Anybody got any better ideas?
Thanks,
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果区域和区域在您的应用程序中实际上足够相似,您可能需要考虑对两者使用相同的表(并使用标志列来区分给定行代表的类型)。在这种情况下,任何区域/区域都可以有一个父区域/区域,并且每个扇区都必须有一个父区域/区域。
例如:
If Areas and Zones are effectively similar enough in your application, you might want to consider using the same table for both (and use a flag column to distinguish which type a given row represents). In this case, any Area/Zone could have a parent Area/Zone, and every Sector must have a parent Area/Zone.
For instance:
你不能将其建模为 IS-A 关系吗?区域始终是一个区域,扇区始终是一个区域。
区域和扇区之间存在可选关系。
这是一个奇怪的设计,但嘿,你已经要求任何替代方案。
您可以在扇区表中添加一个或多个 zone_id 列,如果您想让自己变得非常困难,请向这些列添加外键约束。
can't you model it as an IS-A relationship? A zone is always an area and a sector is always an area.
There is an optional relationship between area and sector.
Its an odd design but hey you've asked for any alternative.
You can add one or more zone_id columns in the sector table, and if you want to make it really hard for yourself, add foreign key constraints to those.