I'm new to Backbone and Firebase. I'm using Backfire, have a collection:
var UsersCollection = Backbone.Firebase.Collection.extend({
model: UserModel,
firebase: new Firebase( "https://xxxxxx.firebaseio.com/users" ),
});
The model itself is not tied to Firebase (was getting "Invalid Firebase reference created" error):
var UserModel = Backbone.Model.extend({
defaults: function() {
return {
email: "example@example.com"
};
}
});
In my View, I instantiate the collection, and I get the data okay, and I can add new models to the collection, as follows:
this.allUsers = new UsersCollection();
...
this.allUsers.add( userData );
Works great, new user records appear on Firebase. However, let's say I now want to grab a given user's model and update its data:
var userRecord = this.allUsers.findWhere( {email: email} );
userRecord.set( {age: age} );
This updates the model locally but the changed model is NOT getting synced to Firebase. I tried userRecord.save();
afterwards but it triggers a "circular reference" error. Per the docs, set()
should do it bur clearly something is off :(