diff --git a/backbone.js b/backbone.js index c793c652..469c479a 100644 --- a/backbone.js +++ b/backbone.js @@ -342,7 +342,7 @@ // A model is new if it has never been saved to the server, and lacks an id. isNew : function() { - return this[this.idAttribute] == null; + return this.id == null; }, // Call this method to manually fire a `change` event for this model. diff --git a/test/model.js b/test/model.js index 3bb8ffe4..7ad0d71f 100644 --- a/test/model.js +++ b/test/model.js @@ -175,8 +175,10 @@ $(document).ready(function() { var model = new MongoModel({id: 'eye-dee', _id: 25, title: 'Model'}); equals(model.get('id'), 'eye-dee'); equals(model.id, 25); + equals(model.isNew(), false); model.unset('_id'); equals(model.id, undefined); + equals(model.isNew(), true); }); test("Model: set an empty string", function() {