持久化模式 - 基于规则的观察者
我正在尝试向应用程序添加功能,用户可以订阅所做的更改:
- 到另一个实体(由任何用户)
- 由另一个用户(到任何其他实体)
- 两者的组合(最后一个是可选的,但使这个问题更具挑战性)
我想知道如何最好地将这些规则保存到数据库中。
我自然倾向于为每个给定的实体(包括用户本身)添加一个附加的 UserSubscription 表/实体(例如 PublisherUserSubscription、BookUserSubscription、UserUserSubscription),
这意味着订阅将在强制完整性的情况下持久保存。然而,这似乎会导致我需要的表数量迅速增加,并且如果我稍后更改订阅模型,可能会导致非常脆弱的设计。 (每个现有表都可能需要更新)。
鉴于这是一个相当普遍的现实场景,我预计会有一些围绕此的模式。有人能推荐一些吗?
I'm trying to add functionality to an app where a user can subscribe for changes made either:
- To another entity (by any user)
- By another user (to any other entity)
- A combination of the two (this last one's optional, but makes the problem more challenging)
I'm wondering how best to persist these rules to the database.
I'm naturally tending towards for each given entity (including the user itself), I add an addition UserSubscription table / entity (eg, PublisherUserSubscription, BookUserSubscription, UserUserSubscription)
This means that subscriptions will be persisted with integrity enforced. However, it seems that this can quickly baloon in terms of the number of tables I'll need, and can lead to a very brittle design, should I later change the subscription model. (Every existing table could need to be updated).
Given this is a fairly commonplace real-world scenario, I'd expect there'd be some patterns around this. Can anyone suggest some?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我讨厌建议实体/属性/值模式,但为什么不使用一个简单的表,例如:
每个场景 ObjectToUser/UserToObject 一个表?
如果您想要观察特定的实体(例如特定的书),请将对象的主键添加到 EAV 模式中。
然后,如果您需要检查规则是否被触发,您可以从表中的“ObjectClass”中查询“ObjectId”,并触发列出的任何规则。
I hate to suggest the Entity/Attribute/Value pattern, but why not have a simple table such as:
One table for each scenario ObjectToUser/UserToObject ?
If you want to have a particular entity be observed, say a particular book, have the Object's Primary Key be added to the EAV pattern.
Then if you need to check if a rule is fired, you query on "ObjectId" from "ObjectClass" from your table and fire whatever rule is listed.