mercredi 25 février 2015

Ember creating via accepts_nested_attributes duplicates children

I have a parent and children models which I'm saving via accepts_as_nested_attributes in Rails. I have this working fine after changes to my serializer in Ember like so:



App.FooSerializer = DS.ActiveModelSerializer.extend DS.EmbeddedRecordsMixin,
serialize: (record, options) ->
json = @_super(record, options)

# re-write the keys for accepts_nested_attributes_for
json.bars_attributes = json.bars
delete json.bars

json

attrs:
bars: {
serialize: 'records',
deserialize: 'ids'
}


However when I save a new record I end up with the bars for the new record being duplicated in Ember those new records with a null id and then the saved versions with their appropriate id.


I was trying to look at the serializer to figure out if I can do something there to properly modify the records in Ember rather than duplicating them with the ones from the response but started to get a bit lost after the payload is normalized.





Aucun commentaire:

Enregistrer un commentaire