I am having an issue working with Ember Data Fixture Adapter. When saving a record, all of the record's hasMany associations are lost. I have created a simple JS Bin to illustrate the issue: http://jsbin.com/aqiHUc/42/edit
If you edit any of the users and save, all the projects disappear.
This is using Ember 1.0.0 and the latest canary build of Ember Data.
I am not sure if I am doing something wrong or if this is an issue with Ember Data.
Thanks
To answer my question, the DS.JSONSerializer.serializeHasMany
seems to only processes and serialize manyToNone and manyToMany relationship types. You can override this behaviour by using a custom serializer for the model:
var get = Ember.get;
App.UserSerializer = DS.RESTSerializer.extend({
serializeHasMany: function(record, json, relationship) {
var key = relationship.key;
var relationshipType = DS.RelationshipChange.determineRelationshipType(record.constructor, relationship);
if (relationshipType === 'manyToNone' || relationshipType === 'manyToMany' || relationshipType === 'manyToOne') {
json[key] = get(record, key).mapBy('id');
}
}
});
Still not quite sure if this is a bug or if this is the desired/expected behaviour.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With