Reputation: 759
I have two Aggregate root, Publisher and 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 ?
Upvotes: 1
Views: 2337
Reputation: 533
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.
Upvotes: 3