Currently I have a model setup like this
App.Specialty = DS.Model.extend({
//specialty_id: attr(),
name: attr()
});
It has a primaryKey being returned from the json api called specialty_id
instead of id
(what ember data probably expects).
So not fiddling with anything ember data gets two objects where one it uses the id as whatever parameter and the second one it gets the right object but has id as undefined.
How can I let ember data know that it should be searching for specialty_id
instead?
For the entire app
App.ApplicationSerializer = DS.RESTSerializer.extend({
primaryKey: '_id'
});
For a single type
App.FooSerializer = DS.RESTSerializer.extend({
primaryKey: '_id'
});
You will still refer to it as id
on the model, but Ember Data will serialize/deserialize it to _id
during transfer.
Example: http://emberjs.jsbin.com/OxIDiVU/635/edit
Read More about it here: http://emberjs.com/api/data/classes/DS.RESTSerializer.html#property_primaryKey
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With