Skip to content

Commit 29fe5f7

Browse files
committed
Fix django-json-api#784 Clear m2m relationships instead of deleting them 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.
1 parent 2adfb5b commit 29fe5f7

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

rest_framework_json_api/views.py

+2
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ def remove_relationships(self, instance_manager, field):
286286
for obj in instance_manager.all():
287287
setattr(obj, field_object.name, None)
288288
obj.save()
289+
elif hasattr(instance_manager, 'clear'):
290+
instance_manager.clear()
289291
else:
290292
instance_manager.all().delete()
291293

0 commit comments

Comments
 (0)