Using primary keys with Ember Data

后端 未结 5 1538
情歌与酒
情歌与酒 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:26

    In case the solution suggested by Nikita doesn't work (didn't for me using revision 11 of ember-data), here is how I changed the primary key when working with the RESTAdapter:

    App.Adapter = DS.RESTAdapter.extend({
        serializer: "App.MySerializer"
    });
    
    // notice we extend the RESTSerializer, not Serializer!
    App.MySerializer = DS.RESTSerializer.extend({
        primaryKey: function(type) {
            return '_id'; // you get it...
        }
    });
    

    I'm aware that this probably won't help the OP anmore but I still post it as it may be helpful for some of you.

提交回复
热议问题