5

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?

user1952811
  • 2,398
  • 6
  • 29
  • 49
  • 1
    I think you can get the answer from http://stackoverflow.com/questions/14821980/using-primary-keys-with-ember-data – fanta Jun 10 '14 at 22:52

1 Answers1

10

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

Kingpin2k
  • 47,277
  • 10
  • 78
  • 96