Skip to content

PATCH returns data:[] relationships #318

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
joshhubers opened this issue Jun 28, 2018 · 5 comments
Closed

PATCH returns data:[] relationships #318

joshhubers opened this issue Jun 28, 2018 · 5 comments
Labels

Comments

@joshhubers
Copy link
Contributor

joshhubers commented Jun 28, 2018

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.

@joshhubers
Copy link
Contributor Author

I should also mention I'm using v2.2.5 as I have not upgraded to Core 2.1 yet.

@jaredcnance
Copy link
Contributor

Thanks for reporting this. I plan on picking this up on Monday if no one gets to it by then.

@joshhubers
Copy link
Contributor Author

Update: I have upgraded to core 2.1, and am using v2.3.3 and still have the bug.

@jaredcnance
Copy link
Contributor

@joshhubers actually, I'm unable to repro. Can you take a look at the test here:

d9d1f65#diff-3291fcbe5d589cd25e4f538a16f78aadR148

And let me know if you're doing something different? Are you updating the relationship in the PATCH request?

@joshhubers
Copy link
Contributor Author

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

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

No branches or pull requests

2 participants