Best way to delete all related things to a domain model
As an example there is a picture down below. On a picture there is admin model (one of domain models) there is subscription which can't exist without admin and subscription has some other things that can't exist without subscription. The question is where to delete them and how
![No description](https://cdn.answeroverflow.com/1318411185976246383/0BE0CA63-B4F9-48C0-8465-7336182761FA.png)
5 Replies
you either put a delete on the relationships in the database or when deleting from your service you search the data and delete it from the leaf to the root aggregate
service meaning something like cqrs or service meaning it can be done in a repository?
by service i mean class, like a repository eventually
the important part to me is that when you pick with a way to do this (so all in db or all in code) you stick with it
also if you want to do this you have to pay attention with internal consistency, so that every time a delete touches these objects the behavior is always the same
i would do this either with a layer or with a group of (abstract) queries that then are extended from the specific feature ("why are these objects being deleted?")
it depends on the size of the project
so shortly it means that I should enforce the same delete behavior across every use case in my project and use case could add some additional logic?
i only say you have to find a way to respect your model's constraints
and having a univocal place where this happens is usually the easiest way to do it