app/assets/javascripts/backbone-nested-attributes/model.js in backbone-nested-attributes-0.2.2 vs app/assets/javascripts/backbone-nested-attributes/model.js in backbone-nested-attributes-0.2.3
- old
+ new
@@ -49,19 +49,24 @@
attributes[key] = nested
return attributes
}
- function configureNestedAttributesEvents(model) {
- if (!model._hasNestedAttributesEventsConfigured) {
- model.on('sync', function () {
- _(model.relations).each(function (relation) {
- var collection = model.get(relation.key)
+ function clearDeletedModelsFor(model) {
+ _(model.relations).each(function (relation) {
+ var collection = model.get(relation.key)
- collection.deletedModels.reset()
- })
+ collection.each(function (nestedModel) {
+ clearDeletedModelsFor(nestedModel)
})
+ collection.deletedModels.reset()
+ })
+ }
+
+ function configureNestedAttributesEvents(model) {
+ if (!model._hasNestedAttributesEventsConfigured) {
+ model.on('sync', clearDeletedModelsFor)
model._hasNestedAttributesEventsConfigured = true
}
}
function configureEventBubbling(model, nested, relation) {
\ No newline at end of file