Ember Data is picky about JSON responses. I have some 'irregular keys' in the response from my server, and according to the guide I can map those onto the adapter.
http://emberjs.com/guides/models/the-rest-adapter/#toc_underscored-attribute-names
However, Ember says: Type Error: Object has no method 'map'
How do I map keys to a model?
I am using Ember v1.0.0 and Ember Data v1.0.0-beta.1
App.ApplicationAdapter = DS.RESTAdapter.extend({
namespace: 'api',
host: 'http://localhost:8080'
});
App.Customer = DS.Model.extend({
name: DS.attr('string')
});
App.CustomersRoute = Ember.Route.extend({
model: function () {
var store = this.get('store');
return store.findAll('customer');
}
});
App.ApplicationAdapter.map('App.Customer', {
name: { key: 'Name' }
});
UPDATE:
Looking at the Ember Data docs, it seems I can add the map functionality to the adapter like this:
DS.Adapter.reopenClass({
map: DS._Mappable.generateMapFunctionFor('attributes', function(key, newValue, map) {
var existingValue = map.get(key);
for (var prop in newValue) {
if (!newValue.hasOwnProperty(prop)) { continue; }
existingValue[prop] = newValue[prop];
}
})
});
I tried this, but map doesn't seem to be working. There are no more errors, but the mapped attribute(s) are null. Why?