0
votes

with all the changes to ember-data ( see here ), I am struggling to determine if the json format has changed as well.

for example, if I have the following model

App.Contact  = DS.Model.extend({
    contactGroupGUID: DS.attr('string'),
    email: DS.attr('string'),
    firstName: DS.attr('string'),
    id: DS.attr('string'),
    lastName: DS.attr('string'),
    notes: DS.attr('string')
})    

what is the json field names for contactGroupGUID, firstName and lastName ?

is it still first_name and last_name ? (I never figured out what contactGroupGUID should be ;) )

thanks

1

1 Answers

1
votes

Ember Data 1.0.beta.1 does not does not do anything to the keys in JSON payloads. Underscored properties are no longer camelcased by default. Also, related model id references are no longer expected to have _id or _ids suffixes. So if you passed the following in 0.13:

{ post: {
  { title: "The future is now",
    extended_title: "The future is now: be prepared",
    author_id: 17,
    comment_ids: [7165, 8937, 9384]
  }
}

1.0.beta.1 is expecting:

{ post: {
  { title: "The future is now",
    extendedTitle: "The future is now: be prepared",
    author: 17,
    comment: [7165, 8937, 9384]
  }
}

Key conversion can be configured (c.f. https://github.com/emberjs/data/blob/master/TRANSITION.md#rest-adapter-and-serializer-configuration) and there will likely be more configuration options, e.g. where to look for related models, in the future.