2

I'm using BackFire's Backbone.Firebase.Collection. I have listeners on an input field for updating the model. The value is validated and then the model is updated through

this.model.save({'title': val});

While the data does get updated at Firebase's end (checked through Forge), I get the following error in console:

Uncaught TypeError: Firebase.update failed: First argument contains a cyclic object value (collection.models.0.collection.models.0.collection.models.0.collection.models.0.collection.models.0.collection.models.0.collection.models.0.collection.models.0.collection.models...)

The app works fine if I replace Firebase with Localstorage for testing. Even with BackFire, the data is getting updated.

Mike-O
  • 844
  • 1
  • 11
  • 16
  • 1
    Models in a collection have a reference to the collection which has a reference to the model which ... so there's your cycle. So either you're using it wrong or Backfire has a bug and is missing a `toJSON` call somewhere. – mu is too short Dec 15 '13 at 18:29
  • Your comment helped me figure out the issue. tl;dr: Needed to use `mode.set` instead of `model.save` The doc says "BE AWARE! You do not need to call any functions that will affect remote data. If you call fetch or sync on the collection, the library will ignore it silently." While for collections, it ignores fetch and sync, but if I use `model.save` which delegates to `Backbone.sync`, backfire doesn't ignore it and throws this error. Thanks! – Shashank Mehta Dec 15 '13 at 19:45
  • You might want to right that up as an answer and then accept it, might be a good reference for other people. You're allowed to answer your own questions and accept those answer (but you have to wait AFAIK 24 hours to accept your own answer). – mu is too short Dec 15 '13 at 20:37

1 Answers1

1

Don't call model.save() if you're using Backbone.Firebase.Collection, simply edit the model using model.set() and the collection will be updated.

Anant
  • 7,408
  • 1
  • 30
  • 30