scoursen / django-softdelete

Soft delete for Django ORM, with support for undelete.
Other
376 stars 102 forks source link

Prevent all model entities from being deleted for OneToOneField relations #100

Closed matthewelwell closed 1 year ago

matthewelwell commented 1 year ago

Fixes #99

As an extra thought, I am wondering whether there should be some configuration (either in the settings or on the models themselves) as to whether the __class__.objects..all().delete() is EVER called. It seems super dangerous to me and I'm not sure what it achieves? I would suggest that this code should not be run by default.

For our use case, for example, we would be looking for a couple of options perhaps:

  1. Just don't do anything. Since the parent entity has been soft deleted, these entities can remain in the database without any referential integrity issues. This would work in cases where the OneToOne related fields are only shown in the context of their parent.
  2. Raise an exception. Clearly something has gone awry but instead of deleting everything, we should surface an exception.

I'd be keen to understand (here or on the issue I raised) what the logic behind adding these lines of code was so that a decision can be made on the above.

scoursen commented 1 year ago

I've been lax in merging PRs, but I just merged one earlier that now gives a conflict for this branch. Once you resolve that, I'll merge this one.

matthewelwell commented 1 year ago

Thanks @scoursen, I've resolved the conflict now.