mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
#4917 - Remove O(n) queries in m2m updates
This commit is contained in:
parent
a0602bce4c
commit
64ff8c5b0b
|
@ -491,11 +491,14 @@ class ManyRelatedField(Field):
|
|||
self.fail('not_a_list', input_type=type(data).__name__)
|
||||
if not self.allow_empty and len(data) == 0:
|
||||
self.fail('empty')
|
||||
|
||||
values = list(self.child_relation.get_queryset.filter(pk__in=data))
|
||||
missing_primary_keys = set(v.pk for v in values) - set(data)
|
||||
|
||||
if missing_primary_keys:
|
||||
self.fail('missing_ids', ids_not_found=list(missing_primary_keys))
|
||||
|
||||
return [
|
||||
self.child_relation.to_internal_value(item)
|
||||
for item in data
|
||||
]
|
||||
return values
|
||||
|
||||
def get_attribute(self, instance):
|
||||
# Can't have any relationships if not created
|
||||
|
|
Loading…
Reference in New Issue
Block a user