From 5310996d09a8b5772e0a0810a327575f02d3a42a Mon Sep 17 00:00:00 2001 From: Steve Mason Date: Thu, 11 Aug 2011 08:53:42 +0100 Subject: [PATCH 1/2] Test for unset attributes not being returned by changedAttributes --- test/model.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/model.js b/test/model.js index 7ad0d71f..bfb499ea 100644 --- a/test/model.js +++ b/test/model.js @@ -170,6 +170,14 @@ $(document).ready(function() { equals(i, 2, 'Unset does not fire an event for missing attributes.'); }); + test("Model: unset and changedAttributes", function() { + var model = new Backbone.Model({a: 1}); + model.unset('a', {silent: true}); + var changedAttributes = model.changedAttributes(); + ok('a' in changedAttributes, 'changedAttributes should contain unset properties'); + equals(changedAttributes.a, undefined); + }); + test("Model: using a non-default id attribute.", function() { var MongoModel = Backbone.Model.extend({idAttribute : '_id'}); var model = new MongoModel({id: 'eye-dee', _id: 25, title: 'Model'}); From 98877ff4b67259f45c74799c148bd5b30e13db87 Mon Sep 17 00:00:00 2001 From: Steve Mason Date: Thu, 11 Aug 2011 08:53:55 +0100 Subject: [PATCH 2/2] Fix for unset attributes not being returned by changedAttributes --- backbone.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backbone.js b/backbone.js index b2e49322..0a026452 100644 --- a/backbone.js +++ b/backbone.js @@ -374,6 +374,12 @@ changed[attr] = now[attr]; } } + for (attr in old){ + if (!(attr in now)){ + changed = changed || {}; + changed[attr] = void 0; + } + } return changed; },