claytondaley / drf-writable-nested

Writable nested model serializer for Django REST Framework
Other
1 stars 2 forks source link

Deeply nested relations #5

Open bennettrogers opened 3 years ago

bennettrogers commented 3 years ago

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 commented 3 years ago

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()