Skip to content

Properly handle select/include pairs #2786 #2809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions spec/ParseObject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: jasmine also has toBeDefined()

expect(gameScore.get("score")).toBe(1234);
done();
}).catch(err => {
jfail(err);
done();
})
});
});
9 changes: 6 additions & 3 deletions src/RestQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(','));
Expand All @@ -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) => {
Expand Down