I am using BackBone relational as very useful extension of Backbone.js.
I have an issue however after saving a backbone relational model with a 1 - M relationship.
The problem I am seeing is that, after model.save(), the add: is fired once again for every related model in the collection. This causes an issue with my view as the models are rendered a second time in the master view.
My master view is set up as follows:
//master view
initialize: function(){
_.bindAll(this, 'render', 'renderRelated');
this.model.bind('change', this.render);
this.model.bind('add:related', this.renderRelated);
}
This works great on first load and when adding new related models. The problem is that when save is called on the parent model the add:related
is fired again for every nested model even when the models have IDs etc. It seems that the save fully repopulates the related collection.
I'm wondering how have other people gotten around this? I was considering:
- attaching the nested view to each related model
- bind rm:related to a method that will remove the view from the master view
This seems pretty hacky to me, is very inefficient and will causes a flashing effect for the end user as the sub views are removed and added again.
As part of this I was also trying to bind to the reset:related
but that does not seem to fire after the save.