Sergey
Sergey

Reputation:

Defining many-to-many relationships in DDD

Are many-to-many table structures defined as Value Objects in DDD? What if my many-to-many structure has a unique id? Also, what about 1-to-many relationships? For instance, if i have 2 structures Post & Comment with 1-to-many (respectively) wouldn't Comment be a Value Object since it technically cannot exist without a corresponding Post? But what if it has a unique Id (Comment_Id)? That makes it identifiable and therefore a non-value object entity? So, which is it?

Thanks!

Upvotes: 4

Views: 1208

Answers (1)

Mike Chaliy
Mike Chaliy

Reputation: 26648

You are probably do not need DDD for blog. DDD is more about business logic. You will not have enough business logic to benefit from DDD.

If you still want to use DDD, not a problem. Some guidelines:

  1. If you want something to be referensable from outside of the business logic, it should be entity. So if you need reference to comments (otherwise you will not be able to manage them effectively) you need your comments to be an entities.
  2. You have to maximize persistence ignorance. This means that could not expose identifiers to your business logic.
  3. Many-to-many and one-to-many relationships are modeled with plain collections. The ORM tool should map this collections properly.

Hope this helps to avoid DDD in your situation.

Upvotes: 1

Related Questions