0
votes

I'm getting the following error while using DS.EmbeddedRecordsMixin when my records have embedded data:

TypeError: Cannot read property 'typeKey' of undefined

I'm using Ember CLI 0.1.2 with Ember 1.7.0 and Ember Data 1.0.0#beta11

My adapters:

Application Adapter - /app/adapters/application.js (RestAdapter):

import DS from 'ember-data';
import config from '../config/environment';

export default DS.RESTAdapter.extend({
    namespace: config.APP.RestAdapterNamespace,
    host: config.APP.SERVER_LOCATION
});

Adapter in question - /app/adapters/screen.js (screenSlideGroups should be embedded):

import ApplicationAdapter from './application';
import DS from 'ember-data';

export default ApplicationAdapter.extend(DS.EmbeddedRecordsMixin, {
    attrs: {
        screenSlideGroups: { embedded: 'always' }
    }
});

Model: /app/models/screen.js

import DS from 'ember-data';

export default DS.Model.extend({
  name: DS.attr('string'),
  path: DS.attr('string'),
  screenSlideGroups: DS.hasMany('screen-slide-group')
});

Example of data returned from the API:

{
  "screen":[
     {
        "id":1,
        "name":"Weather",
        "path":"weather",
        "screenSlideGroups":[
           {
              "id":1,
              "screen":1,
              "slideGroup":1,
              "order":1
           }
        ],
        "lastUpdated":"2014-09-18T18:26:25.69"
     },
     {
        "id":2,
        "name":"Front Lobby",
        "path":"frontlobby",
        "screenSlideGroups":[

        ],
        "lastUpdated":"0001-01-01T00:00:00"
     }
  ]
}

I also tried removing screen from the embedded record, incase the backwards reference could screw it up, but it didn't make a difference. As far as I can tell, the EmbeddedRecordsMixin adapter I created may not be getting used at all.

Any ideas on what may have gone wrong here?

1

1 Answers

0
votes

Turns out I misread the documentation, and DS.EmbeddedRecordsMixin should be on the Serializer, NOT the Adapter.

The correct implementation was as follows:

/app/serializers/screen.js:

import DS from 'ember-data';

export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
    attrs: {
        screenSlideGroups: { embedded: 'always' }
    }
});