san4ezy / django_softdelete

MIT License
79 stars 21 forks source link

Soft delete and DELETE CASCADE #3

Closed foucdeg closed 3 years ago

foucdeg commented 3 years ago

I have this model:

class MyParent(models.Model):
    # whatever

class MyModel(SoftDeleteModel):
    parent = models.ForeignKey(MyParent, on_delete=models.CASCADE)

What happens if I delete a Parent which has children MyModel? Does the child get physically deleted, or soft deleted and the foreign key set NULL?

san4ezy commented 3 years ago

Hi, @foucdeg !

Currently, the cascade deletion is not changed and it works as the Django standard functionality.

Soft-deletion works only with the models, you specifically inherit with the SoftDeleteModel class. This library overrides the model's delete method and the model queryset's delete method.

foucdeg commented 3 years ago

So the child does get physically deleted. It's probably a good thing to document.

san4ezy commented 3 years ago

Thanks! It's a good remark. I have documented it already.

reyniel26 commented 2 years ago

How about this?

class MyParent(SoftDeleteModel):
    # whatever

class MyModel(SoftDeleteModel):
    parent = models.ForeignKey(MyParent, on_delete=models.CASCADE)

I tried to soft delete the parent yet the child model is not soft deleted. How to soft delete the child model by soft deleting the parent ?

sudarshaana commented 1 year ago

How about this?

class MyParent(SoftDeleteModel):
    # whatever

class MyModel(SoftDeleteModel):
    parent = models.ForeignKey(MyParent, on_delete=models.CASCADE)

I tried to soft delete the parent yet the child model is not soft deleted. How to soft delete the child model by soft deleting the parent ?

Facing same problem

mahdisaibridge commented 1 year ago

I'm facing the same problem here, should I use the Signal and handle it myself?