Skip to content

Commit

Permalink
Merge pull request #532 from flovilmart/sub-keys-column-names-restric…
Browse files Browse the repository at this point in the history
…tions

Fix problems with _keys in nested objects
  • Loading branch information
gfosco committed Feb 20, 2016
2 parents eb03405 + fbdd89c commit d9b94c7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
29 changes: 29 additions & 0 deletions spec/ParseObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1736,4 +1736,33 @@ describe('Parse.Object testing', () => {
});
});


it("should create nested keys with _", done => {
const object = new Parse.Object("AnObject");
object.set("foo", {
"_bar": "_",
"baz_bar": 1,
"__foo_bar": true,
"_0": "underscore_zero",
"_more": {
"_nested": "key"
}
});
object.save().then( res => {
ok(res);
return res.fetch();
}).then( res => {
const foo = res.get("foo");
expect(foo["_bar"]).toEqual("_");
expect(foo["baz_bar"]).toEqual(1);
expect(foo["__foo_bar"]).toBe(true);
expect(foo["_0"]).toEqual("underscore_zero");
expect(foo["_more"]["_nested"]).toEqual("key");
done();
}).fail( err => {
console.error(err);
fail("should not fail");
done();
})
})
});
8 changes: 3 additions & 5 deletions src/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ function transformUpdateOperator(operator, flatten) {

// Converts from a mongo-format object to a REST-format object.
// Does not strip out anything based on a lack of authentication.
function untransformObject(schema, className, mongoObject) {
function untransformObject(schema, className, mongoObject, isNestedObject = false) {
switch(typeof mongoObject) {
case 'string':
case 'number':
Expand Down Expand Up @@ -683,10 +683,8 @@ function untransformObject(schema, className, mongoObject) {
objectId: objData[1]
};
break;
} else if (key[0] == '_' && key != '__type') {
} else if (!isNestedObject && key[0] == '_' && key != '__type') {
throw ('bad key in untransform: ' + key);
//} else if (mongoObject[key] === null) {
//break;
} else {
var expectedType = schema.getExpectedType(className, key);
var value = mongoObject[key];
Expand All @@ -700,7 +698,7 @@ function untransformObject(schema, className, mongoObject) {
}
}
restObject[key] = untransformObject(schema, className,
mongoObject[key]);
mongoObject[key], true);
}
}
return restObject;
Expand Down

0 comments on commit d9b94c7

Please sign in to comment.