mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-08 03:00:26 -04:00
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:
@@ -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.
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user