Skip to content

Commit 6ddc776

Browse files
committed
Fixes mismatching behavior in including keys
- When including a key, parse.com would set to undefined all not found pointer, not parse-server
1 parent 1bfee45 commit 6ddc776

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

spec/ParseObject.spec.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use strict";
12
// This is a port of the test suite:
23
// hungry/js/test/parse_object_test.js
34
//
@@ -1791,6 +1792,55 @@ describe('Parse.Object testing', () => {
17911792
console.error(err);
17921793
fail("should not fail");
17931794
done();
1795+
});
1796+
});
1797+
1798+
it('should have undefined includes when object is missing', (done) => {
1799+
let obj1 = new Parse.Object("AnObject");
1800+
let obj2 = new Parse.Object("AnObject");
1801+
1802+
Parse.Object.saveAll([obj1, obj2]).then(() => {
1803+
obj1.set("obj", obj2);
1804+
// Save the pointer, delete the pointee
1805+
return obj1.save().then(() => { return obj2.destroy() });
1806+
}).then(() => {
1807+
let query = new Parse.Query("AnObject");
1808+
query.include("obj");
1809+
return query.find();
1810+
}).then((res) => {
1811+
expect(res.length).toBe(1);
1812+
expect(res[0].get("obj")).toBe(undefined);
1813+
let query = new Parse.Query("AnObject");
1814+
return query.find();
1815+
}).then((res) => {
1816+
expect(res.length).toBe(1);
1817+
expect(res[0].get("obj")).not.toBe(undefined);
1818+
return res[0].get("obj").fetch();
1819+
}).then(() => {
1820+
fail("Should not fetch a deleted object");
1821+
}, (err) => {
1822+
expect(err.code).toBe(Parse.Error.OBJECT_NOT_FOUND);
1823+
done();
17941824
})
1795-
})
1825+
});
1826+
1827+
it('should have undefined includes when object is missing on deeper path', (done) => {
1828+
let obj1 = new Parse.Object("AnObject");
1829+
let obj2 = new Parse.Object("AnObject");
1830+
let obj3 = new Parse.Object("AnObject");
1831+
Parse.Object.saveAll([obj1, obj2, obj3]).then(() => {
1832+
obj1.set("obj", obj2);
1833+
obj2.set("obj", obj3);
1834+
// Save the pointer, delete the pointee
1835+
return Parse.Object.saveAll([obj1, obj2]).then(() => { return obj3.destroy() });
1836+
}).then(() => {
1837+
let query = new Parse.Query("AnObject");
1838+
query.include("obj.obj");
1839+
return query.get(obj1.id);
1840+
}).then((res) => {
1841+
expect(res.get("obj")).not.toBe(undefined);
1842+
expect(res.get("obj").get("obj")).toBe(undefined);
1843+
done();
1844+
});
1845+
});
17961846
});

src/RestQuery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ function replacePointers(object, path, replace) {
509509
}
510510

511511
if (path.length == 0) {
512-
if (object.__type == 'Pointer' && replace[object.objectId]) {
512+
if (object.__type == 'Pointer') {
513513
return replace[object.objectId];
514514
}
515515
return object;

0 commit comments

Comments
 (0)