Skip to content

Commit

Permalink
Fix getting attribute that is an empty object. Closes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
powmedia committed May 1, 2012
1 parent 11c1ed4 commit cc7db2f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -72,6 +72,7 @@ Changelog

0.7.1:
- Model.changedAttributes now works with nested attributes.
- Fix getting attribute that is an empty object

0.7:
- Update for Backbone v0.9.2
2 changes: 1 addition & 1 deletion src/deep-model.js
Expand Up @@ -17,7 +17,7 @@
for (var key in obj) {
var val = obj[key];

if (val && val.constructor === Object) {
if (val && val.constructor === Object && !_.isEmpty(val)) {
//Recursion for embedded objects
var obj2 = objToPaths(val);

Expand Down
11 changes: 11 additions & 0 deletions test/deep-model.test.js
Expand Up @@ -53,6 +53,17 @@ test("get: Gets nested attribute values from arrays", function() {
});


test("get: Gets attributes if empty objects", function() {
var model = new Backbone.DeepModel({
foo: {},
bar: []
});

deepEqual(model.get('foo'), {});
deepEqual(model.get('bar'), []);
});


test("set: Sets nested values given a path", function() {
var model = create();

Expand Down

0 comments on commit cc7db2f

Please sign in to comment.