Properly handle select/include pairs #2786 (#2809)

* Regression test for 2786

* Fix issue affecting selcting/including keys
This commit is contained in:
Florent Vilmart
2016-10-07 09:33:55 -04:00
committed by GitHub
parent d8f0f9e158
commit 6979bb430b
2 changed files with 36 additions and 3 deletions

View File

@@ -1955,4 +1955,34 @@ describe('Parse.Object testing', () => {
done();
})
});
it('should handle select and include #2786', (done) => {
let score = new Parse.Object("GameScore");
let player = new Parse.Object("Player");
score.set({
"score": 1234
});
score.save().then(() => {
player.set("gameScore", score);
player.set("other", "value");
return player.save();
}).then(() => {
let query = new Parse.Query("Player");
query.include("gameScore");
query.select("gameScore");
return query.find();
}).then((res) => {
let obj = res[0];
let gameScore = obj.get("gameScore");
let other = obj.get("other");
expect(other).toBeUndefined();
expect(gameScore).not.toBeUndefined();
expect(gameScore.get("score")).toBe(1234);
done();
}).catch(err => {
jfail(err);
done();
})
});
});

View File

@@ -488,7 +488,6 @@ function includePath(config, auth, response, path, restOptions = {}) {
pointersHash[className].add(pointer.objectId);
}
}
let includeRestOptions = {};
if (restOptions.keys) {
let keys = new Set(restOptions.keys.split(','));
@@ -500,10 +499,14 @@ function includePath(config, auth, response, path, restOptions = {}) {
return set;
}
}
set.add(keyPath[i]);
if (i < keyPath.length) {
set.add(keyPath[i]);
}
return set;
}, new Set());
includeRestOptions.keys = Array.from(keySet).join(',');
if (keySet.size > 0) {
includeRestOptions.keys = Array.from(keySet).join(',');
}
}
let queryPromises = Object.keys(pointersHash).map((className) => {