Skip to content

Accessing included data that is only in the primary data #299

Closed
@fusion2004

Description

@fusion2004

So, I'm having an issue that I'm not sure to which gem the fix should go. I'm requesting data from an index and including a relationship which references another record in that same data set, similar to this:

GET /tasks?include=parent

{
  "data": [
    {
      "id": "1",
      "type": "tasks",
      "attributes": {
        "text": "do thing"
      },
      "relationships": {
        "parent": {
          "data": null
        }
      }
    },
    {
      "id": "2",
      "type": "tasks",
      "attributes": {
        "text": "do other thing"
      },
      "relationships": {
        "parent": {
          "data": {
            "id": 1,
            "type": "tasks"
          }
        }
      }
    }
  ]
}

The gem I'm using is jsonapi-resources, and it seems to try and optimize this as shown: If the data you tried to include was in the primary dataset, then don't also add it to the included dataset. I can't seem to find any clear documentation in either the JSON API spec or recommendations regarding this case.

Would you be open to a PR implementing a lookup for included data that also checks the primary dataset? If so, should this gem default to using that fallback, or should it be a configuration setting?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions