Reputation: 837
I have this model:
App.Me = DS.Model.extend({
email: DS.attr('string'),
firstname: DS.attr('string'),
lastname: DS.attr('string')
});
And i'm trying to fetch it, and my response looks like this: {"email":"[email protected]","firstname":"Mads","lastname":"Mylastname"}
Ember then says thw following in my console:
WARNING: Encountered "email" in payload, but no model was found for model name "email" (resolved model name using DS.RESTSerializer.typeForRoot("email")) ember-1.8.0.js:15358
WARNING: Encountered "firstname" in payload, but no model was found for model name "firstname" (resolved model name using DS.RESTSerializer.typeForRoot("firstname")) ember-1.8.0.js:15358
WARNING: Encountered "lastname" in payload, but no model was found for model name "lastname" (resolved model name using DS.RESTSerializer.typeForRoot("lastname")) ember-1.8.0.js:15358
Error: Assertion Failed: The response from a findAll must be an Array, not undefined
So i assume that it is because Ember expects a root object called "me", but how do i rewrite it?
EDIT: Now i got the correct format:
{"me":[{"email":"[email protected]","firstname":"Mads","lastname":"Mylastname"}]} main.js:33
Upvotes: 1
Views: 2876
Reputation: 837
I used the serializer to fix the dataformat like so:
App.MeSerializer = DS.RESTSerializer.extend({
primaryKey: 'email',
extractArray: function (store, primaryType, payload) {
var primaryTypeName = primaryType.typeKey;
var typeName = primaryTypeName,
type = store.modelFor(typeName);
var data = {};
var item = [];
item.push(payload)
data[typeName] = item;
console.log(JSON.stringify(data));
payload = data;
return this._super.apply(this, arguments);
}
});
Upvotes: 2