Skip to content

Relationship Data - missing or by design? #218

@mattgi

Description

@mattgi

Should I always see relationship data, regardless of link config or include query?

By this, I mean /items currently produces:

{
    "data": [
        {
            "type": "items",
            "id": "item-de4e78d3-b2ec-48dd-8dd7-6088881a2bfe",
            "attributes": {
                "type": 0,
                "title": "New York",
                "cover": null,
                "slug": null,
                "version": 1
            },
            "relationships": {
                "owner": {
                    "links": {
                        "self": "/items/item-de4e78d3-b2ec-48dd-8dd7-6088881a2bfe/relationships/owner",
                        "related": "/items/item-de4e78d3-b2ec-48dd-8dd7-6088881a2bfe/owner"
                    },
                "createdBy": {},
                "updatedBy": {},
                "deletedBy": {}
                }
            }
        }
    ]
}

If I include owner (/items?include=owner):

{
    "data": [
        {
            "type": "items",
            "id": "item-de4e78d3-b2ec-48dd-8dd7-6088881a2bfe",
            "attributes": {
                "type": 0,
                "title": "New York",
                "cover": null,
                "slug": null,
                "version": 1
            },
            "relationships": {
                "owner": {
                    "links": {
                        "self": "/items/item-de4e78d3-b2ec-48dd-8dd7-6088881a2bfe/relationships/owner",
                        "related": "/items/item-de4e78d3-b2ec-48dd-8dd7-6088881a2bfe/owner"
                    },
                    "data": {
                        "type": "users",
                        "id": "user-b607e7dc-3a9d-4360-8495-dd37c4c99de8"
                    }
                },
                "createdBy": {},
                "updatedBy": {},
                "deletedBy": {}
            }
        }
    ],
    "included": [
        {
            "type": "users",
            "id": "user-b607e7dc-3a9d-4360-8495-dd37c4c99de8",
            "attributes": {
                "email": "poo@shorthand.com",
                "firstName": "Matthew",
                "lastName": "Gint2y",
                "slug": "slugger",
                "version": 1
            },
            "relationships": {
                "createdBy": {},
                "updatedBy": {},
                "deletedBy": {}
            }
        }
    ]
}

Even when I am not asking for includes (or if links are turned off), I was expecting the relationships to always have data:

"relationships": {
                "owner": {
                    "data": {
                        "type": "users",
                        "id": "user-b607e7dc-3a9d-4360-8495-dd37c4c99de8"
                    }
                },

Is this expected behavior or am I potentially missing something on my model?

      [HasOne("owner")]
      public virtual User Owner { get; set; }

      public string OwnerId { get; set; }

Based on http://jsonapi.org/format/#document-resource-objects and their { article } snippet, it suggests data should be there.. I must be missing something somewhere?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions