mercredi 29 avril 2015

EmbeddedRecordsMixin not working as expected, what am I missing?

I'm trying to use embedded records in ember data and I think I'm missing something fundamental.

I have two models

app/models/video.js:

export default DS.Model.extend({
  title: DS.attr('string'),
  transcriptions: DS.hasMany('transcription', { embedded: 'always' })
});

app/models/transcription.js:

export default DS.Model.extend({
  video: DS.belongsTo('video')
});

I also have a custom serializer app/serializers/video.js:

export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
  attrs:{
    transcriptions: { embedded: 'always' }
  },  
  extractSingle: function (store, type, payload, id) {
    var data = payload.data;
    return {
      id: data._id,
      title: data.Title,
      transcriptions: [{ id: "1" }] 
  };
},

I would expect that this would result in my video model being populated with transcriptions being an array of transcription object but instead I get the following error:

"Error while processing route: videos.show" "Assertion Failed: Ember Data expected a number or string to represent the record(s) in the transcriptions relationship instead it found an object. If this is a polymorphic relationship please specify a type key. If this is an embedded relationship please include the DS.EmbeddedRecordsMixin and specify the transcriptions property in your serializer's attrs object."

Any suggestions of what I'm doing wrong here would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire