PATCH returns data:[] relationships
See original GitHub issueWhen I patch to an endpoint the relationship returns data: [], which isn’t always true.
For example, if I had ingredients and recipes, I query for recipes?include=ingredients
and I will get the included ingredients as expected.
However, if I PATCH to recipe, the relationship returns an empty array, even though relationships exist For example:
{
"data":{
"attributes":{
"id":203,
"title":"Cake",
},
"relationships":{
"ingredients":{
"links":{...},
"data":[ ] <------- Shouldn't be empty or present?
}
},
"type":"recipes",
"id":"203"
}
}
In my case I’m building an ember app, so ember thinks that the relationships just magically disappear and content on the page will disappear on update.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
rest - What is the best practice for managing relationships ...
What is the best practice for managing relationships using POST and PATCH in a RESTful API when the opposite entity already exists?
Read more >Updating resources
By combining the examples above, both attributes and relationships can be updated using a single PATCH request. Response body. PATCH requests can be...
Read more >JsonAPI - Updating the relationship for a resource
1 Answer 1 ... If you want to change who the author is, that's a relationship on the article. You would patch /articles/:id...
Read more >Please clarify: 200 OK response when updating relationships
So if a PATCH on resource including relationship A was targeted, causing a change to untargeted relationship B, we need to return 200....
Read more >PATCH method on exposed REST services
PATCH method allows a new HTTP method when exposing REST APIs that applies partial modifications to a resource.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jaredcnance Thanks for the test. The test ran fine and looks like the situation I was having.
Turns out there was an initializer in the default constructor, assigning an empty list to the property.
i.e.
So the serializer believed that there was a relationship with no data.
@joshhubers actually, I’m unable to repro. Can you take a look at the test here:
https://github.com/json-api-dotnet/JsonApiDotNetCore/pull/332/commits/d9d1f659f672070268066bd59184772eb810ea89#diff-3291fcbe5d589cd25e4f538a16f78aadR148
And let me know if you’re doing something different? Are you updating the relationship in the
PATCH
request?