Tell ember.js to use different key for its model's “id”

穿精又带淫゛_ 提交于 2019-12-03 09:07:41

You need to specify the attribute that should be used as the primaryKey in your Adapter. If you want the slug property to serve as your Post model id, define the primaryKey on your Adapter like this:

DS.RESTAdapter.map('App.Post', {
  primaryKey: 'slug'
});

Update

As of Ember-data version 1.0.0-beta.7 canary, you need to do this instead of the above snippet:

App.PostSerializer = DS.JSONSerializer.extend({
  primaryKey: 'slug'
});
j10io

I'm not an ember pro, but I had wanted to use a slug instead of an ID recently and did this, wondering if this what you're after? https://stackoverflow.com/a/14967337/472852

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!