lux icon indicating copy to clipboard operation
lux copied to clipboard

Relationships not present in included resources

Open nickschot opened this issue 8 years ago • 7 comments

When requesting to include records for relationships of the requested record (i.e. my-model?include=something1,something2, the relationships of those records are not included in the response.

I think this throws off at least ember-data a bit as it won't recognise any relationships for those records.

EDIT: some more information for this added below.

Example request: GET /my-model/1?include=something

Example response from Lux (with the missing relationships for the records in "included"):

{
  "data": {
    "id": "1",
    "type": "my-model",
    "attributes": {
         ...
    },
    "relationships": {
      "something": {
        "data": {
          "id": "30",
          "type": "something"
        },
        "links": {
          "self": "http://localhost:5000/something/30"
        }
      }
    }
  },
  "included": [
    {
      "id": "30",
      "type": "something",
      "attributes": {
        ...
      },
      "links": {
        "self": "http://localhost:5000/something/30"
      }
    }
  ],
  "links": {
    "self": "http://localhost:5000/my-model/1?include=something"
  },
  "jsonapi": {
    "version": "1.0"
  }
}

nickschot avatar Jan 16 '17 14:01 nickschot

I believe this is actually an error in the ember-data implementation, not Lux. See this section of the JSON API spec.

I'm going to close this issue for now.

zacharygolba avatar Jan 16 '17 21:01 zacharygolba

-- oops, thought it was another issue.

EDIT: improvements to the first post to better clarify what this specific feature request is.

nickschot avatar Jan 16 '17 21:01 nickschot

Can be enabled by toggling this boolean: https://github.com/postlight/lux/blob/7bf2478bd0305d65549f9b9fe98997f51dc07ae0/src/packages/serializer/index.js#L728

nickschot avatar May 18 '17 18:05 nickschot

@nickschot I believe the lines have shifted since your link. Did you mean formatRelationships?

lehni avatar May 31 '17 08:05 lehni

They seem to have! And I do! Thanks for pointing that out. I modified the comment with a more resilient link.

nickschot avatar May 31 '17 08:05 nickschot

How / where are you setting this value to true?

lehni avatar May 31 '17 08:05 lehni

I am not currently. It can be set to true in the lux codebase as pointed out in the comment as an initial fix for this issue, some tests would need to be added though.

nickschot avatar May 31 '17 08:05 nickschot