Skip to content
This repository has been archived by the owner on Aug 25, 2018. It is now read-only.

Commit

Permalink
Make Backbone.Firebase.Collection.create return newly created model, c…
Browse files Browse the repository at this point in the history
…loses #15
  • Loading branch information
anantn committed Nov 22, 2013
1 parent a6d4f7d commit 39d90dc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ Firebase, triggering a `remove` event both locally and on all other clients.
Messages.remove(someModel);
```

### create(value)
Cretes and adds a new model to the collection. The newly created model is
returned, along with a `id` property (uniquely generated by Firebase).

``` js
var newModel = Messages.create({bar: "foo"});
Messages.get(newModel.id);
```

Backbone.Firebase.Model
-----------------------
This is a special model object that will automatically synchronize its
Expand Down
5 changes: 2 additions & 3 deletions backbone-firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@
},

create: function(model, options) {
this._log("Create called. Consider using Collection.add!");
options = options ? _.clone(options) : {};
if (options.wait) {
this._log("Wait option provided to create, ignoring.");
Expand All @@ -267,8 +266,8 @@
if (!model) {
return false;
}
this.add([model], options);
return model;
var set = this.add([model], options);
return set[0];
},

reset: function(models, options) {
Expand Down
2 changes: 1 addition & 1 deletion backbone-firebase.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 39d90dc

Please sign in to comment.