Skip to content

Commit

Permalink
Fix django-json-api#784 Clear m2m relationships instead of deleting t…
Browse files Browse the repository at this point in the history
…hem during PATCH

Calling PATCH on an M2M RelationshipView when there were already some relationships was breaking. This was because the related objects were being deleted instead of just clearing the relationship and starting afresh.
  • Loading branch information
rohithpr authored and sliverc committed Jun 13, 2020
1 parent f87eeaf commit ea63eb5
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rest_framework_json_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ def remove_relationships(self, instance_manager, field):
for obj in instance_manager.all():
setattr(obj, field_object.name, None)
obj.save()
elif hasattr(instance_manager, 'clear'):
instance_manager.clear()
else:
instance_manager.all().delete()

Expand Down

0 comments on commit ea63eb5

Please sign in to comment.