Backbone-relational
Backbone-relational copied to clipboard
Destroy event arguments differ depending model's nesting level.
This is a cracker. Given a hierarchy of: [A] has many [B] has many [C].
When an [A] is destroyed, the "destroy" listener receives (model, collection, options) where:
- model.collection is set, and still contains the model being destroyed.
- collection still contains the model being destroyed
When a [C] is destroyed, the "destroy" listener receives (model, collection, options) where:
- model.collection is not set (is undefined)
- collection does not contain the model being destroyed
Fiddle: http://jsfiddle.net/mglilley/Yz6jY/1/
Why would the destroy listener for a model at the top of the hierarchy be fired before the model has been removed from its collection, and after for a model at the bottom?