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

Deeply nested relations #5

Open
bennettrogers opened this issue Aug 29, 2021 · 1 comment
Open

Deeply nested relations #5

bennettrogers opened this issue Aug 29, 2021 · 1 comment

Comments

@bennettrogers
Copy link

Thank you for creating this fork/PR – it has already solved a few issues I've had with nested serializers.

Is it possible to use these mixins to support deeply nested serializers? If I've got models/serializers in a parent -> child -> grandchild configuration, can I PATCH a parent object with data containing both new and updated child and grandchild objects? If not, is there a known/recommended way of manually creating serializers that support this?

@claytondaley
Copy link
Owner

partial doesn't behave cleanly in deeply nested serializers as discussed here. I'm not even sure cascading partial is the right way to do it.

For example, you may be willing to make a partial update to UserProfile but it doesn't really make sense to just update the street_number in a nested Address object. You really want the UserProfileSerializer to be partial and the AddressSerializer to be normal. I believe the base implementation supports this.

If you want to support a more complex stack, I would try creating a different serializer hierarchy. For example,

PartialUserSerializer():
    address = AddressSerializer()
    father = PartialParentSerializer()
    mother = PartialParentSerializer()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants