jeudi 18 juin 2015

How to combine primaryKey modification with belongsTo in Ember Data

I've got an odd problem where I need to combine two concepts. When used individually, the techniques works, when combined, they fail. Basically, when I try to enter a primaryKey into a custom serializer, the belongsTo relationship depending on the primary key fails.

Consider this JSBin that demonstrates the problem.

My API doesn't return an ID in the payload so I use a custom serializer to point to the correct primaryKey.

App.ContactSerializer = DS.RESTSerializer.extend({
    primaryKey: 'user_id'
});

But this breaks my existing relationship defined in the model.

App.Contact = DS.Model.extend({
  email: DS.attr('string'),
  user: DS.belongsTo('user', {async: true})
});

How can I have my cake and eat it too?

JSBin Demo

Aucun commentaire:

Enregistrer un commentaire