Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

matthewelwell
Copy link
Contributor

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
Copy link
Owner

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
Copy link
Contributor Author

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

@scoursen scoursen merged commit ba5fb22 into scoursen:master Feb 28, 2023
@matthewelwell matthewelwell deleted the fix/onetoonefield-hard-deletes-all-model-entitites branch February 28, 2023 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OneToOneField relations deletes entire table if not marked as soft delete
2 participants