Skip to content

Commit d9b94c7

Browse files
committed
Merge pull request #532 from flovilmart/sub-keys-column-names-restrictions
Fix problems with _keys in nested objects
2 parents eb03405 + fbdd89c commit d9b94c7

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

spec/ParseObject.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,4 +1736,33 @@ describe('Parse.Object testing', () => {
17361736
});
17371737
});
17381738

1739+
1740+
it("should create nested keys with _", done => {
1741+
const object = new Parse.Object("AnObject");
1742+
object.set("foo", {
1743+
"_bar": "_",
1744+
"baz_bar": 1,
1745+
"__foo_bar": true,
1746+
"_0": "underscore_zero",
1747+
"_more": {
1748+
"_nested": "key"
1749+
}
1750+
});
1751+
object.save().then( res => {
1752+
ok(res);
1753+
return res.fetch();
1754+
}).then( res => {
1755+
const foo = res.get("foo");
1756+
expect(foo["_bar"]).toEqual("_");
1757+
expect(foo["baz_bar"]).toEqual(1);
1758+
expect(foo["__foo_bar"]).toBe(true);
1759+
expect(foo["_0"]).toEqual("underscore_zero");
1760+
expect(foo["_more"]["_nested"]).toEqual("key");
1761+
done();
1762+
}).fail( err => {
1763+
console.error(err);
1764+
fail("should not fail");
1765+
done();
1766+
})
1767+
})
17391768
});

src/transform.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ function transformUpdateOperator(operator, flatten) {
586586

587587
// Converts from a mongo-format object to a REST-format object.
588588
// Does not strip out anything based on a lack of authentication.
589-
function untransformObject(schema, className, mongoObject) {
589+
function untransformObject(schema, className, mongoObject, isNestedObject = false) {
590590
switch(typeof mongoObject) {
591591
case 'string':
592592
case 'number':
@@ -683,10 +683,8 @@ function untransformObject(schema, className, mongoObject) {
683683
objectId: objData[1]
684684
};
685685
break;
686-
} else if (key[0] == '_' && key != '__type') {
686+
} else if (!isNestedObject && key[0] == '_' && key != '__type') {
687687
throw ('bad key in untransform: ' + key);
688-
//} else if (mongoObject[key] === null) {
689-
//break;
690688
} else {
691689
var expectedType = schema.getExpectedType(className, key);
692690
var value = mongoObject[key];
@@ -700,7 +698,7 @@ function untransformObject(schema, className, mongoObject) {
700698
}
701699
}
702700
restObject[key] = untransformObject(schema, className,
703-
mongoObject[key]);
701+
mongoObject[key], true);
704702
}
705703
}
706704
return restObject;

0 commit comments

Comments
 (0)