ddd 中的多对多关系
我有两个聚合根,发布商和营销活动:
- 1 个营销活动可以注册多个发布商,
- 1 个发布商可以分配给多个营销活动。
这意味着 MToM 关系
,所以在 Publisher 类中,我创建了
List<Campaign> _campaigns;
,在 Campaign 类中
List<Publisher> _publishers;
,我创建了包含列(id、publisherID、CampaignID)的表,
但我听说应该避免 MtoM,我该怎么做?以上描述正确吗?
I have two Aggregate root, Publisher and Campaign:
- 1 campaign can have multiple publisher registered,
- 1 publisher can have assigned to multiple campaign.
that means MToM relationship
so in Publisher class, i created
List<Campaign> _campaigns;
and in Campaign class
List<Publisher> _publishers;
I have created table with columns (id, publisherID,CampaignID)
But i have heard that MtoM should be avoided, how can i do that ? Do above depiction is correct ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确实,您应该避免多对多关系,因为此类关联通常会带来复杂性。实现此目的的一种方法是强制执行遍历方向。因此,在您的域中,如果最常见的操作是针对发布商及其营销活动,您可以认为只有在特殊情况下才需要双向关系,而是在营销活动存储库中使用一种方法来检索给定营销活动的所有发布商。然后,您可以从您的广告活动类别中删除发布商列表
,或者当然反之亦然。
It's true you should avoid many-to-may relationsships, because of the complexity that typically follows such associations. One way to do this is to enforce a traversal direction. So in your domain, if the most common operations is against a publisher and it's campaigns, you could argument that the bidirectional relation is only needed in special cases, and instead have a method on your campaign repository which retrieves all publishers for a given campaign. Then you could remove the list of publishers from your campaign class
Or of course the other way around.