Let's say I have two entities User and Item. The sole behavior in the domain between these two entities is that a user can like an item. Since there is no restriction on how many items a user can like, this many-to-many relation can be large.
I don't think it makes sense performance-wise to have User contains a list of items they liked in its model or the other way around, since I'll have to load a potentially large collection of items in order to add just one item. From domain design point of view, it also doesn't make sense to me to have either entity reference the other in their fields as no behavior require the presence of a collection of items or users.
I do need to keep this relationship as the UI needs to display a list of items a user liked and a list of users that liked an item. The requirement can be served by a read model but I still need a domain concept to capture this relationship so that it can be persisted.
One way I can come up with is to introduce a relation type of aggregate, say UserLikeItem, and have method user.like(item) return an instance of UserLikeItem which I can then use UserLikeItemRepository to persist.
Is this a valid solution? What is the natural way in DDD to model this type of large but non-behavioral relations?
User
IMO. It also allows you to capture additional info such as the time the item was liked, in what context, etc. The same AR could be used for unlike as well, but maybe you need to find a better name for it. – BottomryLikeCounter
to the Item, so that you can display the total like count for an item without having to hit theUseLikeItem
data source. – Gualtiero