Skip to content

Document include options for Compound Documents  #256

@scottfisk

Description

@scottfisk

With #250 pulled in we now have options to include relations to form compound documents:

  1. Include resources related to the primary data by default.
  2. Include resources related to the primary data through use of a request parameter which customizes which related resources should be returned

Example Current Implementation

  1. default include posts
class UserSerializer(serializers.Serializer):
    name = serializers.CharField(max_length=200)
    # PostSerializer included directly on the serializer
    posts = PostSerializer(many=True, read_only=True)

    class JSONAPIMeta:
        # included_resources specifys resources to include by default
        included_resources = ['posts']
  1. param include posts
class UserSerializer(serializers.Serializer):
    name = serializers.CharField(max_length=200)
    # PostSerializer NOT included directly on the serializer, ResourceRelatedField is 
    # specified as default
    posts = relations.ResourceRelatedField(
            source='post_set', many=True, read_only=True) 

    # specifies serializer to use when passing in the `include` param
    included_serializers = {
        'posts': PostSerializer,
    }

We should probably document this. We can even copy the examples above with a bit of explanation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions