ember.js - How to combine primaryKey modification with belongsTo in Ember Data -


i've got odd problem need combine 2 concepts. when used individually, techniques works, when combined, fail. basically, when try enter primarykey custom serializer, belongsto relationship depending on primary key fails.

consider jsbin demonstrates problem.

my api doesn't return id in payload use custom serializer point correct primarykey.

app.contactserializer = ds.restserializer.extend({     primarykey: 'user_id' }); 

but breaks existing relationship defined in model.

app.contact = ds.model.extend({   email: ds.attr('string'),   user: ds.belongsto('user', {async: true}) }); 

how can have cake , eat too?

jsbin demo

after googling, came appears workable solution:

revised jsbin example basically, can use normalize function in serializer add exptected id value non-standard value api supplies.

// match serializer adapter...(activemodel) // use normalize slip in id api app.contactserializer = ds.activemodelserializer.extend({     normalize: function(typeclass, hash, prop) {         hash.id = hash.user_id;         return this._super(typeclass, hash, prop);     } }); 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -