Merge pull request #438 from gravof/master

Model is no longer considered to be new if its id is a falsey value
This commit is contained in:
Jeremy Ashkenas
2011-06-29 18:03:00 -07:00
2 changed files with 6 additions and 2 deletions

View File

@@ -342,7 +342,7 @@
// A model is new if it has never been saved to the server, and has a negative
// ID.
isNew : function() {
return !this.id;
return this.id == null;
},
// Call this method to manually fire a `change` event for this model.

View File

@@ -96,7 +96,11 @@ $(document).ready(function() {
a = new Backbone.Model(attrs);
ok(a.isNew(), "it should be new");
attrs = { 'foo': 1, 'bar': 2, 'baz': 3, 'id': -5 };
ok(a.isNew(), "any defined ID is legal, negative or positive");
a = new Backbone.Model(attrs);
ok(!a.isNew(), "any defined ID is legal, negative or positive");
attrs = { 'foo': 1, 'bar': 2, 'baz': 3, 'id': 0 };
a = new Backbone.Model(attrs);
ok(!a.isNew(), "any defined ID is legal, including zero");
});
test("Model: get", function() {