Skip to content

Include type and id for relationship, without full resource include #46

@camjackson

Description

@camjackson

In my response, I want to include relationship information in the main resource, but I don't want to include the whole resource in the "included" section, mostly because the other resource has no attributes, so it's redundant.

I.e., I want to generate a response that looks like the following:

{
    "data": {
        "id": "5",
        "type": "things",
        "attributes": {
            "name": "A Thing",
        },
        "links": {
            "self": "/things/5"
        },
        "relationships": {
            "otherThing": {
                "data": {
                    "type": "otherThings",
                    "id": "123"
                }
            }
        }
    }
}

When I serialize without any :include, then I get:

    "relationships": {
        "otherThing": {
        }
    }

When I serialize with include: 'otherThing', then I get:

    "relationships": {
        "otherThing": {
            "type": "otherThings",   <--- I want this information
            "id": "123"              <--- and also this
        }
    }
"included": [    <--- But I don't need any of this
    {
        "type": "otherThings",
        "id": "123",
        "attributes": {},
        "links": {
            "self": "/otherThings/123"
        }
    }
]

Is there a way to get this middleground?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions