I have two aggregates Parent and Child, say. A Parent can have many Childs (Children). A Child can only belong to one Parent.
I need to keep track of a sort order of the Child entities so that when you get the Child entities for a Parent the list is in that order.
The obvious database schema is the following:
However, an invariant of the model needs to be that this order is well defined. So if you have a method on Child, Child.SetOrdinal(int) say, then this invariant is not protected (there is nothing stopping you setting two Childs to ordinal 3). I don't want to pull it all together into one large aggregate.
The alternative I see is a database like the following:
Where I have introduced a link table to store the relationship and order, this would be inside the Parent aggregate, where the invariant could be protected. This does add complexity to the database however.
Is there another way, or is the first, simpler version not that bad?