question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PATCH returns data:[] relationships

See original GitHub issue

When 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:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
joshhuberscommented, Jul 6, 2018

@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.

public Person()
{
  TodoItems = new List<TodoItems>();
} 

So the serializer believed that there was a relationship with no data.

1reaction
jaredcnancecommented, Jul 5, 2018

@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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found