kurko / ember-json-api

JSON API adapter for Ember Data.
MIT License
254 stars 62 forks source link

Singular Resources and pluralized keys #13

Closed ColtonProvias closed 10 years ago

ColtonProvias commented 10 years ago

According to the currently published JSON API spec, singular resources are to be wrapped in arrays and keyed with the plural form of the resource type.

ember-json-api expects:

{
  "post": {
    "id": 1,
    "title": "First Post"
  }
}

And what JSON API-compliant implementations provide:

{
  "posts": [{
    "id": 1,
    "title": "First Post"
  }]
}
gr0uch commented 10 years ago

Are you sure you are using this adapter and not the basic REST Adapter that comes with Ember Data by default?

ColtonProvias commented 10 years ago

Yes. The only error message I receive from it is "Error while loading route: undefined." If I change it to the RESTAdapter format while still using the JsonApiAdapter, it then works.

Code that returns that error: http://pastebin.com/FdBfs6qG

And the JSON being provided:

{
  "projects": [{
    "id": 1,
    "name": "New Name"
  }]
}
gr0uch commented 10 years ago

Can you confirm whether or not it calls this method? That is the relevant code here I think.

ColtonProvias commented 10 years ago

Strangely, it doesn't even look like it hits the serializer. Tracing it, the last function from ember-json-api being called is buildURL.

Here's the full error output from the browser:

Error while loading route: undefined ember.js:3521
logToConsole ember.js:3521
defaultActionHandlers.error ember.js:35513
triggerEvent ember.js:35588
trigger ember.js:34618
Transition.trigger ember.js:34434
(anonymous function) ember.js:34291
invokeCallback ember.js:10013
publish ember.js:9683
publishRejection ember.js:10111
(anonymous function) ember.js:18380
DeferredActionQueues.flush ember.js:6127
Backburner.end ember.js:6215
Backburner.run ember.js:6254
Ember.run ember.js:6664
hash.success ember-data.js:10004
j jquery.js:3047
k.fireWith jquery.js:3159
x jquery.js:8183
(anonymous function) jquery.js:8530
ColtonProvias commented 10 years ago

I found the issue. Bower is for some reason installing an old version of ember-data. Sorry about that!