Save on a model with Ember-data returns error


#1

when I save, a post request happens, my server creates the record, then returns the new record with an id, but ember gives me this error:

No model was found for '_id

Any idea why?

My json looks like this:

{ "_id": “53094e7e502b5a6828000011”, “content”: “fx”, “title”: “fx”, “created”: “2014-02-23T01:27:26.238Z” }


#2

apparently it’s because it wants the json from the server to be its own way and to be wrapped in article { }.

But even with that, when I try to do what the persisting records part of the guide says here:

var post = store.createRecord('post', {
  title: 'Rails is Omakase',
  body: 'Lorem ipsum'
});

var self = this;

function transitionToPost(post) {
  self.transitionToRoute('posts.show', post);
}

function failure(reason) {
  // handle the error
}

post.save().then(transitionToPost).catch(failure);

// => POST to '/posts'
// => transitioning to posts.show route

it doesn’t work, it returns a useless object, supposedly a promise, but no data is contained which I can pass on to my other route like the demo :frowning:

my code is here:


#3

Wrap your object programmatically:

App.ArticleSerializer = DS.RESTSerializer.extend({
  extractSingle: function(store, type, payload, id, requestType) {
    payload = { article: payload };
    return this._super(store, type, payload, id, requestType);
  },
});

#4

thank you, can you please tell me where the documentation is for this?