Skip to content

links object in POST response dirtying relationship #7

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

Open
deepan83 opened this issue Feb 26, 2017 · 6 comments
Open

links object in POST response dirtying relationship #7

deepan83 opened this issue Feb 26, 2017 · 6 comments

Comments

@deepan83
Copy link

deepan83 commented Feb 26, 2017

Say I do a POST to create a photo with a photographer relationship,

POST /photos HTTP/1.1
Content-Type: application/vnd.api+json
Accept: application/vnd.api+json

{
  "data": {
    "type": "photos",
    "attributes": {
      "title": "Ember Hamster",
      "src": "http://example.com/images/productivity.png"
    },
    "relationships": {
      "photographer": {
        "data": { "type": "people", "id": "9" }
      }
    }
  }
}

The following JSON API compliant response to the POST makes the photographer relationship dirty (owing to the links object in the response),

{
  "data": {
    "id": 1,
    "type": "photos",
    "attributes": {
      "title": "Ember Hamster",
      "src": "http://example.com/images/productivity.png"
    },
    "relationships": {
      "photographer": {
        "links": {
           "self": "/api/photos/1/relationships/photographer",
           "related": "/api/photos/1/photographer" 
         },
        "data": { "type": "people", "id": "9" }
      }
    }
  }
} 

This means that a subsequent PATCH operation on this record (triggered by an update to title for example) will pass the photographer relationship in the request, despite the client not modifying it. Is there a way this can be avoided?

@danielspaniel
Copy link
Owner

What is the issue then .. are you using keepOnlyChanged mixin? and want to not resend this relationship?

@deepan83
Copy link
Author

Yes, am using the mixin and prefer not to send this relationship

@danielspaniel
Copy link
Owner

ok .. you want to dig in there and find out why this is being flagged as changed? or you want me to?

@deepan83
Copy link
Author

deepan83 commented Feb 26, 2017

Yeah am up for helping with this. Raised the issue to know if there was any existing workaround to this. Will do a PR once I get to the bottom of it.

@danielspaniel
Copy link
Owner

I have not seen this because I did not test with links payload .. so just needs a test or two to figure out what is going on. But I am not sure it is fixable though .. but if you dig in and see strange things, let me know. I will bring out the flashlight and goggles.

@ezekg
Copy link
Contributor

ezekg commented Mar 3, 2017

@deepan83 Just for giggles, does the latest version fix this issue? Sounds the same as #8.

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

3 participants