You must include an `id` for (subclass of DS.Model) in a hash passed to `push`


#1

Beginning to think I’m going mad:

###The setup

Ember: 1.7.0
Ember Data : 1.0.0-beta.9
Handlebars : 1.3.0
jQuery     : 2.1.1

I’m trying to implement a simple blog app. The posts route:

export default = Ember.Route.extend({
  model: function() {
    return this.store.find('post');
  }
});

A call to the server is made at the response (as shown in the Chrome developer tools) looks like this:

{"posts":
     ["{\"draft\": true, 
        \"title\": \"Test\", 
        \"updated_at\": \"2014-08-30T11:36:01.406000\", 
        \"text\": \"\", 
        \"created_at\": \"2014-08-30T11:36:01.406000\", 
        \"views\": 0, 
        \"id\": 1, 
        \"slug\": \"test\"}"]
}

However I get the following error:

Error while processing route: posts.index Assertion Failed: You must include an `id` for (subclass of DS.Model) in a hash passed to `push` Error: Assertion Failed: You must include an `id` for (subclass of DS.Model) in a hash passed to `push`

I don’t understand - since the post returned from the server includes an id - any ideas on what I’m missing?


#2

Ok, seems the issue was with the server serialization to json the “…” in the response noted above was the clue.

Sorting json serialization to ensure the response is this:

{"posts": 
    [{"views": 0, 
      "text": "", 
      "created_at": ["2014-08-30", "11:36:01"], 
      "title": "Test", 
      "updated_at": ["2014-08-30", "11:36:01"], 
      "id": 1, 
      "draft": true, 
      "slug": "test"}]
}

sorted it.