Skip to content

Many to Many relations between Aggregates #139

Answered by Sairyss
nilaxann65 asked this question in Q&A
Discussion options

You must be logged in to vote

Similar to this discussion: #132

Solution depends on your use case.

Do you need to have members in a company? Most likely yes, so keep it there.

export class Company {
  members: Member[] 
}

Do you need companies in a Person aggregate? are you using it in some way? if not, there is no need for a relation there. If yes, you can keep a list of company IDs in a Person.

export class Person {
  // ...
  companyIds: string[]
}

To get a role you can load a company and get a role from there, instead of keeping role in two places.

Personally I would not put companies into a Person aggregate, there is no need for it to know about companies in most cases, you have Company aggregate for keeping that …

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@nilaxann65
Comment options

@Sairyss
Comment options

@nilaxann65
Comment options

@Sairyss
Comment options

Answer selected by nilaxann65
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants