Currently developing an app using Ember-cli and having some dificulties with models with 2 words and relationships.
Model residents-profile
//models/residents-profile.js
DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string'),
picture: DS.attr('string'),
phone: DS.attr('string'),
gender: DS.attr('string'),
residentsAccount: DS.belongsTo('residentsAccount')
}
** Model Residents-account **
//models/residents-account.js
DS.Model.extend({
email: DS.attr('string'),
password: DS.attr('string'),
profileId: DS.attr('number'),
residentsProfile: DS.belongsTo('residentsProfile', this.profileId),
});
the model hook on the residents route:
//routes/residents.js
model: function() {
return Ember.RSVP.hash({
residentsProfile: this.store.find('residentsProfile'),
residentsAccount: this.store.find('residentsAccount')
})
}
As soon as I try and fetch just the residents profile, i get an error "residents.index Cannot read property 'typeKey'"
But if I remove the relationship key from residents-profile and call only the residents profile the data is fetched correctly.
I'm using the RESTAdapter and a Restful API,
The models are being returned separately and the response from the server is as follows:
GET /residentsProfile { "residentsProfiles": [{ "id": 20, "picture": null, "phone": null, "firstName": "Rocky", "lastName": "Balboa", "blockId": null, "unitId": null, "createdAt": "2014-09-17 19:54:28", "updatedAt": "2014-09-17 19:54:28", "residentsAccount": [5] }] }
GET /residentsAccount { "residentsAccounts": [{ "id": 5, "email": "[email protected]", "admin": false, "resident": true, "profileId": 20, "createdAt": "2014-09-17 19:54:29", "updatedAt": "2014-09-17 19:54:29", "residentsProfile": [20] }] }
EDIT
Besides the changes proposed by @Kingpin2k, which were spot on, i used setupcontroller in the following way:
setupController: function(controller,
controller.set('residentsAccount', models.residentsAccount);
controller.set('residentsProfile', models.residentsProfile);
}
Now everything works.