The findOne action seems to be returning a wrong response format
Closed this issue · 2 comments
Hi,
First of all I want to thank you. You did a really good job in it.
But when I saw the Ember's DS.RESTAdapter documentation (https://www.emberjs.com/api/ember-data/release/classes/DS.RESTAdapter), in the JSON structure section, I figure out that the response of the findOne action is returning an array instead an object. e.g.
/posts/1 is returning:
{ "posts": [{ "title": "My post", "body": "My post content" }] }
instead of:
{ "posts": { "title": "My post", "body": "My post content" } }
Hi siderlan,
The Ember REST Adapter can actually handle an array response, so the response is technically correct.
Additionally, if you wanted to return a single object, it should be:
{ "post": { "title": "My post", "body": "My post content" } }
instead of:
{ "posts": { "title": "My post", "body": "My post content" } }
Though I am not sure why the docs don't seem to indicate the changes in pluralization for a single object.
At any rate, the returned data should always be flowing through the store internal pushPayload method which can identify array based results.
Are you having an issue with the array response somewhere?
Additionally, the REST Adapter docs indicate the following:
Note that the object root can be pluralized for both a single-object response and an array response: the REST adapter is not strict on this. Further, if the HTTP server responds to a GET request to /posts/1 (e.g. the response to a findRecord query) with more than one object in the array, Ember Data will only display the object with the matching ID.