lundi 8 juin 2015

Serialize embedded record with custom key

I've a model with store attribute in it. Unfortunately store is a reserved word in ember-data so I had to change its name to authStore. I can't change backend API to use new attribute name, so I've created a new serializer just for this model.

Model is:

App.Auth = DS.Model.extend({
  status: DS.attr("string"),
  authStore: DS.belongsTo("store"),
});

If I use following serializer, json sent to server contains the right store key

App.AuthSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
  attrs: {
    authStore: 'store',
  }
});

But I also need to specify embedded: 'always' for authStore attribute and so I've update the serializer to

App.AuthSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
  attrs: {
    authStore: {key: 'store', embedded: 'always'}
  }
});

This way key attribute is ignored and even if authStore is embedded when json is sent to server, key attribute is ignored and it has key authStore instead of store. How can I make both key and embedded attributes work togheter?

I'm using ember-cli 0.2.7 and ember-data 1.0.0-beta.18




Aucun commentaire:

Enregistrer un commentaire