Is there a difference between using create() and push() on collections with Backfire, or is this a possible misunderstanding on my part?
Consider an Animal model and Animals collection setup as follows. Typically, the collection is initialized with an options object containing a fixed zoo_id which is then assigned to new models created. For this example, let's assume the zoo_id value is set at 4.
var Animal = Backbone.Model.extend({
initialize: function(attributes, options) {
console.log("model initializing", attributes, options)
}
}),
Animals = Backbone.Firebase.Collection.extend({
firebase: myFirebaseUrl + "/animal",
initialize: function(models, options) {
this.model = function(attrs, opts) {
return new Animal(_.extend(attrs, {zoo_id: 4}))
};
this.on("add", function(model, collection, options) {
console.log("adding", model, collection, options, model.attributes)
})
}
})
var a= new Animals()
When retrieving data from Firebase, all animal models in the array a[] have zoo_id = 4, as expected.
When I push a new model,
a.push({name: "racoon"})
all logged attribute objects show zoo_id = 4. However, the returned object does not include zoo_id, and the zoo_id is missing for the new entry in the Forge.
On the other hand, when I create a new model,
a.create({name: "ape"})
The console logs show that all attributes have zoo_id = 4, the returned object has zoo_id = 4, and the new entry also contains zoo_id = 4 in the Forge.
If I remove the Firebase extensions and stick to using regular Backbone model and collection similarly, push results in an object with a zoo_id, while create fails due to no URL being set up (as anticipated).
Thank you in advance for any clarifications provided!