1

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 ?

anon
  • 4,578
  • 3
  • 35
  • 54
kamal
  • 739
  • 1
  • 9
  • 21

1 Answers1

3

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.

tschmuck
  • 533
  • 1
  • 5
  • 9