Using primary keys with Ember Data

后端 未结 5 1529
情歌与酒
情歌与酒 2020-12-14 04:10

I\'ve been struggling for the past few days with primary keys and the last version of Ember Data.

I first read how to do it on the

5条回答
  •  伪装坚强ぢ
    2020-12-14 04:41

    I use MongoDB and Ember-Data 1.0.0-beta.6 in my application and the _id posed a problem in Ember 1.4.0 for me too. Here's what I've done to solve the problem, assuming the returned JSON array is nested in the root property "people":

    App.ApplicationSerializer = DS.RESTSerializer.extend({
        normalizeHash: {
            people: function(hash) {
                hash.id = hash._id;
                delete hash._id;
                return hash;
            }
        }
    });
    

    This is, of course, an application-wide serializer but you can limit it to a specific path with something like App.MyPathSerializer = DS.RESTSerializer.extend({ ... });

提交回复
热议问题