Skip to content
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

Clearing a resource relationship #223

Open
bensullivan opened this issue Oct 30, 2019 · 3 comments
Open

Clearing a resource relationship #223

bensullivan opened this issue Oct 30, 2019 · 3 comments

Comments

@bensullivan
Copy link

bensullivan commented Oct 30, 2019

Hi

We have a requirement to be able to clear (make null) an existing relationship on a resource. As far as I'm aware the JSON:API spec supports this (where prior to this example PATCH request, the author relationship was "data": { "type": "people", "id": "1" }):

PATCH /articles/1 HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": {
    "type": "articles",
    "id": "1",
    "relationships": {
      "author": {
        "data": null
      }
    }
  }
}

When I come to deserialise a request like this I am getting a InvalidJsonApiResourceException: Resource must contain at least one of 'data', 'error' or 'meta' nodes.

Assuming my interpretation of the JSON:API spec for this scenario isn't wrong, is there a way to clear resource relationships with jsonapi-converter?

Thanks for your help!

Ben

@bensullivan
Copy link
Author

Hi @jasminb - appreciate you're likely very busy at the moment; I would really appreciate any historical/contextual insight into the above before I begin debugging the code to figure out a path forward for us. Many thanks for your efforts on this library - it's very valuable. Ben

@jasminb
Copy link
Owner

jasminb commented Nov 6, 2019

Hello @bensullivan, internally same logic that is used to parse primary data is used to parse relationship data and thats why the same rules apply. This should be something that can be fixed/made configurable.

Edit: Please disregard this comment, I did not read your question properly.

@jasminb
Copy link
Owner

jasminb commented Nov 6, 2019

Just tested parsing following payload (on both master and develop):

{
  "data": {
    "type": "engineer",
    "id": "id",
    "relationships": {
      "field": {
        "data": null
      },
      "city": {
        "data": null
      }
    }
  }
}

And it correctly produces the desired type with its id set and other values set to null including relationship objects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants