Embedded Model in Ember Data 1.0 Beta

It seems that ember data have many changing up to version 1.0 beta. All works great with version 0.13. now I want update to higher version. In my case we have an embedded model ‘user’

    App.Post = DS.Model.extend({
          subject: DS.attr('string'),
          created: DS.attr('number'),
          fcreated: function(){
              var d =  new Date(this.get('created'));
              return d.toLocaleDateString();

          reporter: DS.belongsTo('user' , {embedded: 'always'})

The Json from server looks like this.

    "posts": [
       "id": "5226f2670364e70ae7d77266",
       "subject": "Text",
       "created": 1325410935048,
       "reporter": {
               "id": "5226f2660364e70ae7d771e2",
               "firstName": "Doris",
               "lastName": "Baumertr"

I get the following error code ‘Uncaught TypeError: Cannot call method ‘toString’ of undefined’. In the ember source code I see, that in ember-data.js line 2236 the function throw the error 'buildRecord: function(type, id, data) … ’ After debugging I see that the properties type is undefined id is set with the correct id and data is undefined?

What is the mistake?

Direct support for embedded models has been removed for now, see 1.0 Transition Guide

It is now necessary to extend the adapter to reorganize the structure to the format ember-data expects. I’m also looking for hints on some specifics in Ember Data 1.0Beta - embedded records

Thanks for post, but I am frustrated with ember data. I tested

App.Adapter.map('post', {
    reporter: { embedded: 'always' }

but I get an error, no matter how you look at it. Or is my Adapter setup false? I used ember data 1.0 beta 1

var  adapter  = DS.RESTAdapter.reopen({
    namespace: 'restws'

App.Store = DS.Store.extend({
    adapter: adapter

Have you read the link?


You need to extend RESTAdapter, and implement the extractSingle method to reorganize the structure.

Yes of course, I read it, but it nothing work. It is really annoying, You don’t which version you should take. If you use ember-data-latest.js there ore other code conventions like in ember-data.pod.js. Boah it’s annoyinnnnnnng :frowning:

It does work - but you need to make sure you name the payload attributes specifically for your embedded model name and your model attribute names. I just verified that it works.