Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: save pass through values #2

Merged
merged 1 commit into from
Jul 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions drf_writable_nested/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ def _extract_relations(self, validated_data):

if isinstance(field, serializers.ListSerializer) and \
isinstance(field.child, serializers.ModelSerializer):
if field.source not in validated_data:
if field_name not in validated_data:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

通常 field_name == field.source,但如果不同時,應該 pop field_name 而非 field.source
如下,應該 pop product_data 而非 product

product_data = ProductSerializer(soure='product')

# Skip field if field is not required
continue

validated_data.pop(field.source)
validated_data.pop(field_name)

reverse_relations[field_name] = (
related_field, field.child, field.source)
related_field, field.child, field_name)

if isinstance(field, serializers.ModelSerializer):
if field.source not in validated_data:
if field_name not in validated_data:
# Skip field if field is not required
continue

if validated_data.get(field.source) is None:
if validated_data.get(field_name) is None:
if direct:
# Don't process null value for direct relations
# Native create/update processes these values
continue

validated_data.pop(field.source)
validated_data.pop(field_name)
# Reversed one-to-one looks like direct foreign keys but they
# are reverse relations
if direct:
Expand Down