lundi 28 septembre 2015

JSON API response and ember model names

A quick question about the JSON API response key "type" matching up with an Ember model name.

If I have a model, say "models/photo.js" and I have a route like "/photos", my JSON API response looks like this

{
  data: [{
    id: "298486374",
    type: "photos",
    attributes: {
      name: "photo_name_1.png",
      description: "A photo!"
    }
  },{
    id: "298434523",
    type: "photos",
    attributes: {
      name: "photo_name_2.png",
      description: "Another photo!"
    }
  }]
}

I'm under the assumption that my model name should be singular but this error pops up

Assertion Failed: You tried to push data with a type 'photos' but no model could be found with that name

This is, of course, because my model is named "photo"

Now in the JSON API spec there is a note that reads "This spec is agnostic about inflection rules, so the value of type can be either plural or singular. However, the same value should be used consistently throughout an implementation."

So,

tl;dr Is the "Ember way" of doing things to have both the model names and the JSON API response key "type" both be singular? or does it not matter as long as they match?




Aucun commentaire:

Enregistrer un commentaire