Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fusion2004 opened this issue Sep 14, 2018 · 5 comments
Closed

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

fusion2004 opened this issue Sep 14, 2018 · 5 comments
Assignees

Comments

@fusion2004
Copy link
Contributor

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?

@senid231
Copy link
Member

@fusion2004 I think it should be configurable behavior (by default it should not lookup up in dataset)

@fusion2004
Copy link
Contributor Author

Alrighty, hopefully we'll have time soon to package this into a PR!

senid231 added a commit to senid231/json_api_client that referenced this issue Oct 3, 2018
@senid231 senid231 self-assigned this Jan 14, 2019
senid231 added a commit to senid231/json_api_client that referenced this issue Jan 14, 2019
senid231 added a commit to senid231/json_api_client that referenced this issue Jan 15, 2019
@Fivell
Copy link
Contributor

Fivell commented Jan 18, 2019

@senid231 maybe just a bug in jsonapi-resources, seems out of spec

@senid231
Copy link
Member

@Fivell it's not a bug - it's a feature :)

really I think that it's nice, when you doesn't add same object twice - to data and included.
I've added optional support of this in #299

@fusion2004
Copy link
Contributor Author

@senid231 Thanks for doing that, I never ended up getting the time to come back to this. Your implementation looks much simpler than what we hacked together, too.

senid231 added a commit that referenced this issue Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants