Open fcoppey opened 2 years ago
I have the same issue. After I check the Django & safedelete source code, this is because you set the Null=True in your model.
https://docs.djangoproject.com/en/3.2/_modules/django/db/models/deletion/
this is quit annoying as I must keep Null=True for some models, is there a workaround?
I’ve found a workaround by saving the pk list of related soft deleted objects before the soft deletion and then reassigning the parent id to these after the soft deletion... quite cumbersome. is any willing to make a patch for this bug? my level of coding is not high enough unfortunately... @Gagaro ?
Indeed I'm not sure how to fix that, maybe we should have our own CASCADE which does not set the other field as null.
I'll gladly review a PR if someone is willing to try and patch this.
Having this would be great. For now we are stuck with _safedelete_policy = SOFT_DELETE
. Also we have a regular model R
that is related to a SafeDeleteModel
S
via ForeignKey
. And this regular model R
should be hard deleted, if the related instance of S
is hard deleted and if S
is soft deleted, R
should not be touched.
let’s say I have 2 models A and B, B has a foreign key pointing to A and other have soft delete with policy SOFT_DELETE_CASCADE.
If I soft delete an object in A, then the related object in B gets soft deleted as well BUT it seems its foreign key field point to A is set to NULL... which loses the link between object A and object B when I later want to undelete object A.
Is it the intended behaviour?