I’m doing a save using accepts_nested_attributes_for
and have this setup:
App.Foo = DS.Model.extend
optionValues: DS.hasMany('optionValues')
App.OptionValue = DS.Model.extend
value: DS.attr('string')
App.FooSerializer = DS.ActiveModelSerializer.extend DS.EmbeddedRecordsMixin,
attrs:
optionValues: {
serialize: 'records',
deserialize: 'records'
}
I’ve tried setting up my serializer in rails a few ways, either embedding the objects or including them and the id’s but no matter what the value objects aren’t updated properly. In Ember they remain in a dirty state.
If I add some debugging to the Foo
& OptionValue
serializers in Ember this is what I see when the rails serializer is set to embed :objects
:
fooSerializer: extract [Class, function, Object, "1173", "updateRecord"]
fooSerializer: extractMeta [Class, function, Object]
fooSerializer: extractUpdateRecord [Class, function, Object, "1173", "updateRecord"]
fooSerializer: extractSave [Class, function, Object, "1173", "updateRecord"]
fooSerializer: extractSingle [Class, function, Object, "1173", "updateRecord"]
fooSerializer: normalizePayload [Object]
fooSerializer: normalize [function, Object, "foo"]
fooSerializer: normalizeLinks [Object]
fooSerializer: keyForRelationship ["values", "hasMany"]
fooSerializer: keyForAttribute ["values"]
optionValueSerializer: normalize [function, Object, "option_values"]
optionValueSerializer: normalizeLinks [Object]
optionValueSerializer: keyForAttribute ["value"]
But I never see any extracts being called for the values, I can test this by changing a value for an option value in the rails serializer and then inspecting in ember inspector and the value doesn’t get updated.
I’ve tried not embedding objects & setting it in the serializer in embed as appropriate (optionValues: { serialize: 'records', deserialize: 'ids' }
) but get the same behaviour.
The strange thing is if I create a new Foo
model and save that with new OptionValues
then they get populated properly - the debug trace is the same - no calls to extract etc. on OptionValueSerializer
. Though in the ember inspector I have the old null
id OptionValues
still sticking around.
Notes on versions:
DEBUG: Ember : 1.7.0 ember.js?body=1:14464
DEBUG: Ember Data : 1.0.0-beta.10