I assume this should be fairly simple, but I have not reached the root of the problem, and I'm still studying Ember-Data.
I have two models with a relationship hasManybetween them:
App.User = DS.Model.extend({
displayName: DS.attr('string'),
email: DS.attr('string'),
firstName: DS.attr('string'),
lastName: DS.attr('string'),
location: DS.attr('string'),
messages: DS.hasMany('message')
});
App.Message = DS.Model.extend({
user: DS.belongsTo('user'),
createdAt: DS.attr('date'),
updatedAt: DS.attr('date'),
fullText: DS.attr('string'),
subject: DS.attr('string'),
recipients: DS.attr('string')
});
Ember data retrieves the user from the server, is output as follows:
{
"user":[
{
"id":"3",
"firstName":"A",
"lastName":"User",
"location":"",
"email":"a@user.com",
"displayName":"auser",
"messages":[
{
"id":"3",
"user":"3",
"createdAt":"2014-08-06 20:08:38",
"fullText":"Here is some text",
"recipients":"",
"subject":"Message subject (may not be needed)",
"updatedAt":"2014-08-06 20:08:38"
}
]
}
]
}
However, when Ember tries to populate the repository with this answer, I get the following error:
Error while loading route: TypeError: Cannot read property 'typeKey' of undefined
at Ember.Object.extend.modelFor (http:
at Ember.Object.extend.recordForId (http:
at deserializeRecordId (http:
at deserializeRecordIds (http:
at http:
at http:
at http:
at Object.OrderedSet.forEach (http:
at Object.Map.forEach (http:
at Function.Model.reopenClass.eachRelationship (http:
If you delete or rename relations hasManyfrom my model User, the error will disappear, so for some reason I think my JSON is not built correctly.