I am using BackboneJS for my application. In my scenario, I have a collection (say booksCollection
) with list of all the books (say model Book
). I need to get a certain book based on the id
and pass it to a view. I have the following code:
var book = booksCollection.get(1);
book.save(); // this obtained model is passed to some view, which makes few changes to the model and saves to the server
// booksCollection is a Backbone collection with model: Book
On inspecting book
, I see that it has collection
attribute with all the models in booksCollection
. So, when trying to save (after setting few attributes) this model, I get this error "Too much recursion".
Is the model retured by invoking get
method on a Backbone
collection a readonly
object?
As a quick fix, I am unsetting the collection
attribute in book
and then saving the model
book.unset('collection', { silent: true });
Is this a right approach?
Thanks, Anji