0

In my system, an User can be member of a Team.

I got a domain model called Team which contains id, name, member_count and is_channel. So when I fetch teams in the repository I retrieve the Team domain model.

How would I model the relation between a User and a Team? Because when talking about the relation I don’t care about the member_count and is_channel from the Team model. I even have extra data in the relation which is a role_type.

Should I create a domain model for the relation called TeamScope or something? That contains id, user_id, team_id, role_type?

Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111
guidsen
  • 2,333
  • 6
  • 34
  • 55
  • Are you confusing **domain object** (or **conceptual class**) with **domain model**? `Team` is a *conceptual class* in the *domain model*. I'm similarly confused by the last question, "Should I create a domain model..." There's one domain model, but it contains classes and associations. – Fuhrmanator Nov 17 '17 at 16:31

2 Answers2

0

See my comments on your question regarding your use of terms (model, class, association). I'm assuming you are misusing them when I wrote my answer.

How would I model the relation between a User and a Team? Because when talking about the relation I don’t care about the member_count and is_channel from the Team model (sic). I even have extra data in the relation which is a role_type.

You could use an association class in your domain model to represent this.

enter image description here

Membership can capture the role_type, which really is linked to the association as you have figured out.

member_count is represented with a / at the start, indicating that you'll derive its value from the multiplicity (it's a count of the number of members associated with the team).

You tagged in your question, so I'm going to point to how to implement association classes in Java (not exactly your case, but in Node.js it should be easy to apply).

Fuhrmanator
  • 11,459
  • 6
  • 62
  • 111
  • How would I combine Team and Membership in a later stage? I do not want to create two seperate queries for this.. – guidsen Nov 22 '17 at 15:02
  • If you don't mind users only being on one team at a time, and a role that makes no sense if a user is not associated with a team, you could remove Membership and put role in User. Domain models are geared at capturing the correct requirements of a business process, not necessarily about making the queries simpler. If a user can be on several teams at the same time, it's more complex. – Fuhrmanator Nov 22 '17 at 19:40
0

You should almost definitely model a TeamMember object which contains both a link to the User, a link to the Team, and the role the user plays on that team.

Teams have a list of TeamMembers, Users have a list of TeamMembers. Teams have a MemberCount (not sure if this is static, or dynamic from the count of TeamMembers), and I have no idea what is_channel means...

Rob Conklin
  • 8,806
  • 1
  • 19
  • 23