#Best way to delete child entities in DDD

8 messages · Page 1 of 1 (latest)

unique marten
#

Hi,

Context: In our app, we have Organizations,Teams,Projects,Users and more. An admin can ask to delete the data of the organization. This include all the above mentioned ressources and media related to a project or a user (e.g. profile pictures).

Problem: What would be the best way to delete all data associated to an organization ?

crude gulch
unique marten
#

They are all in the same context

crude gulch
#

I would let the corresponding repository delete everything related to an organization and also raise a domain event to handle media. At least thats the first thing that comes to mind.

#

Or ditch the domain event and do it all in your use case / service

unique marten
#

Right now it's all in my service which I don't like. So you for media, I should emit an event instead ?

crude gulch
#

What don't you like about it? Yeah raising an event from your aggregate root (assuming this is organization) would be enough to have another component deal with it.

unique marten
#

*my organization service.

I didn't use events initially because I didn't want to add complexity. But the issue right now it has the opposite effect. When we implement a new entity linked to an organization or when the definition change (e.g. background picture is added or we create OrganizationSettings), we always needed to change the delete organization function.