From 3145b4db2242aa18ecf582c70c84fdd0c731a3c6 Mon Sep 17 00:00:00 2001 From: Chris Moore Date: Mon, 25 Jul 2011 17:48:09 -0400 Subject: [PATCH] isNew should use id, not idAttribute --- backbone.js | 2 +- test/model.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) 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() {