2

Consider the case of Order/Orderline, where Orderline is an VO collection, in this case persisting Orderline to DB require a separate table with its own set of rows, being an VO this can't have a id as per DDD, how can this mismatch be addressed, given ORM used for persistence. ( validity of the example is subjective but can't come up with a better over at this wee hour, excuse me for that )

Somasundaram Sekar
  • 5,244
  • 6
  • 43
  • 85

1 Answers1

3

The OrderLine table most certainly does not require an Id since it only needs to be related to the relevant Order. The OrderId would be included in the OrderLine table but would not be included in the OrderLine VO as it would be unnecessary since the association is contained within the Order AR.

If your database insists on a primary key, for instance, you could come up within something like OrderId and ProductId or some other combination that makes sense. Even a synthetic key such as a UniqueIdentifier would be OK since this field, too, would be excluded from the domain.

Eben Roux
  • 12,983
  • 2
  • 27
  • 48
  • 1
    Thanks Eben, also referring to Implementing Domain Driven Design by Vaughn Vernon, has come up with a solution to include a Supertype IdentifiedValueObject, hiding the details of generated unique id from the domain. – Somasundaram Sekar Sep 29 '15 at 06:05