-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Hi, I am having an issue with loading nested associations from Sails, which is what I thought this project addressed. I am under the impression that two of the main incompatibilities between Sails and Ember (apart from pluralize and CAML casing) are that the Ember RESTSerializer wants a root element in the JSON response, and that it wants associations to be sideloaded. Using the JSONSerializer seems to take care of the former, but using the SailsRESTAdapter I am still having problems with sideloading. I am using ember-data 1.0.0.beta-10
The data from the server for the SurveyTemplateDisplay model that gets passed to the serializer looks like this:
{
"language": {
"name": "english",
"id":"xxxxxxxxxxxx"
},
"displayName": "My display name for english",
"description": "Test description",
"id": "yyyyyyyyyyyyy"
}
and my ember app looks like this:
window.App = Ember.Application.create();
App.ApplicationAdapter = DS.SailsRESTAdapter.extend({
pathForType: function(type) {
var camelized = Ember.String.camelize(type);
return Ember.String.pluralize(camelized);
},
namespace: 'api/v1'
});
App.Router.reopen({
rootUrl: '/app'
});
App.Router.map(function() {
this.resource('surveyTemplateDisplay', {path: '/surveyDisplay/:id'});
})
App.SurveyTemplateDisplayRoute = Ember.Route.extend({
model: function(params) {
return this.store.find('surveyTemplateDisplay', params.id);
}
});
App.SurveyTemplateDisplay = DS.Model.extend({
displayName: DS.attr('string'),
description: DS.attr('string'),
language: DS.belongsTo('language')
});
App.Language = DS.Model.extend({
name: DS.attr('string')
});The basic problem is that when the JSONSerializer attempts to deserialize the associated model (http://builds.emberjs.com/beta/ember-data.js line 11276), it is expecting there to be a property 'type' on the nested data (the "language": {....} object that is not there. Changing that line from data[key] = store.recordForId(id.type, id.id); to data[key] = store.recordForId(association.key, id.id); seems to do the trick.
Is this an ember-data bug? Can this behavior be overwritten by extending the SailsRESTAdapter or the JSONSerializer instead of hacking ember-data?
Thank you