admin管理员组文章数量:1295306
I am stuck in a situation where I shouldn't return id
field in the API endpoint. I need to tell ember to use slug
field for / instead of id
.
I tried DS.RESTAdapter.map('App.Post', id: {key: 'slug'})
. While this works perfectly fine for App.Post.find("a-slug-name")
, It messes up for App.Post.find()
resulting in adding a new model every time it is called. And also assigning id
to null.
So how should I do this.
I am stuck in a situation where I shouldn't return id
field in the API endpoint. I need to tell ember to use slug
field for / instead of id
.
I tried DS.RESTAdapter.map('App.Post', id: {key: 'slug'})
. While this works perfectly fine for App.Post.find("a-slug-name")
, It messes up for App.Post.find()
resulting in adding a new model every time it is called. And also assigning id
to null.
So how should I do this.
Share asked Aug 3, 2013 at 9:07 dhilipsivadhilipsiva 3,7181 gold badge26 silver badges35 bronze badges2 Answers
Reset to default 10You 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'
});
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./a/14967337/472852
本文标签: javascriptTell emberjs to use different key for its model39s quotidquotStack Overflow
版权声明:本文标题:javascript - Tell ember.js to use different key for its model's "id" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741614455a2388446.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论