一切都必须汇总吗?多对多链接 [英] Does everything have to be an aggregate? Many-to-Many Link

查看:83
本文介绍了一切都必须汇总吗?多对多链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有两个实体
通知和用户。

Say I have two entities Notifications and Users.

我要标记一个用户已看到特定的通知。

I want to mark that a user has seen a specific notification.

通常使用多对多关系
例如UserNotification

This would commonly be done with a many-to-many relationship e.g. UserNotification

因为这种关系没有不变性(我们不在乎所有用户是否都已看到通知),所以这些用户不应出现在通知汇总中。
相反,用户聚合不需要在其上的通知列表

Because there is no invariant around this relationship (we don't care if "all" users have seen the notification) these users shouldn't be on the notification aggregate. On the opposite side, the users aggregate doesn't need a list of notifications on it

因此可以说,UserNotification(这种关系)是自己的总和。
但是,由于我们永远不会通过Id引用此东西,因此它真的真的属于吗?

So that leads to say that the UserNotification (this relationship) is an aggregate of its own. However, because we are never going to reference this thing by Id, does it really really belong as one? It seems like just adding an aggregate for storing the data.

我应该在这里做什么?


  1. 反正只是进行聚合而忽略ID?

  2. 将这些通知放置在一个或多个通知用户上。 (它属于哪一个,是否会使其不增加重量并不会导致并发问题?)

  3. 只是制作一个粗糙表?

  4. 没有ID并保留组合键(允许吗?)的聚合

  1. Just make an aggregate anyway and ignore the id?
  2. Put these notifications on the user or users on notifications. (does it belong on either, and would putting it on one not add weight and cause concurrency issues?)
  3. just make a crud table?
  4. An aggregate without the id and keep the composite key (is that allowed?)

谢谢

推荐答案

通知是否有其自己的生命周期?可以存在通知而无需通知用户吗?

Does a Notification have its own lifecycle? Can a Notification exist without a User to be notified?

我可以想象一个通知只是一个复制到每个受影响用户的值对象。

I could imagine a Notification to simply be a Value Object that gets copied to each affected User.

这篇关于一切都必须汇总吗?多对多链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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