Skip to content
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

Fix includeAll for querying a Pointer and Pointer array #7002

Merged
merged 3 commits into from
Nov 11, 2020
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
84 changes: 84 additions & 0 deletions spec/ParseQuery.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4008,6 +4008,90 @@ describe('Parse.Query testing', () => {
});
});

it('include pointer and pointer array', function (done) {
const child = new TestObject();
const child2 = new TestObject();
child.set('foo', 'bar');
child2.set('hello', 'world');
Parse.Object.saveAll([child, child2]).then(function () {
const parent = new Container();
parent.set('child', child.toPointer());
parent.set('child2', [child2.toPointer()]);
parent.save().then(function () {
const query = new Parse.Query(Container);
query.include(['child', 'child2']);
query.find().then(function (results) {
equal(results.length, 1);
const parentAgain = results[0];
const childAgain = parentAgain.get('child');
ok(childAgain);
equal(childAgain.get('foo'), 'bar');
const child2Again = parentAgain.get('child2');
equal(child2Again.length, 1);
ok(child2Again);
equal(child2Again[0].get('hello'), 'world');
done();
});
});
});
});

it('include pointer and pointer array (keys switched)', function (done) {
const child = new TestObject();
const child2 = new TestObject();
child.set('foo', 'bar');
child2.set('hello', 'world');
Parse.Object.saveAll([child, child2]).then(function () {
const parent = new Container();
parent.set('child', child.toPointer());
parent.set('child2', [child2.toPointer()]);
parent.save().then(function () {
const query = new Parse.Query(Container);
query.include(['child2', 'child']);
query.find().then(function (results) {
equal(results.length, 1);
const parentAgain = results[0];
const childAgain = parentAgain.get('child');
ok(childAgain);
equal(childAgain.get('foo'), 'bar');
const child2Again = parentAgain.get('child2');
equal(child2Again.length, 1);
ok(child2Again);
equal(child2Again[0].get('hello'), 'world');
done();
});
});
});
});

it('includeAll pointer and pointer array', function (done) {
const child = new TestObject();
const child2 = new TestObject();
child.set('foo', 'bar');
child2.set('hello', 'world');
Parse.Object.saveAll([child, child2]).then(function () {
const parent = new Container();
parent.set('child', child.toPointer());
parent.set('child2', [child2.toPointer()]);
parent.save().then(function () {
const query = new Parse.Query(Container);
query.includeAll();
query.find().then(function (results) {
equal(results.length, 1);
const parentAgain = results[0];
const childAgain = parentAgain.get('child');
ok(childAgain);
equal(childAgain.get('foo'), 'bar');
const child2Again = parentAgain.get('child2');
equal(child2Again.length, 1);
ok(child2Again);
equal(child2Again[0].get('hello'), 'world');
done();
});
});
});
});

it('select nested keys 2 level includeAll', done => {
const Foobar = new Parse.Object('Foobar');
const BarBaz = new Parse.Object('Barbaz');
Expand Down
5 changes: 4 additions & 1 deletion src/RestQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,10 @@ RestQuery.prototype.handleIncludeAll = function () {
const includeFields = [];
const keyFields = [];
for (const field in schema.fields) {
if (schema.fields[field].type && schema.fields[field].type === 'Pointer') {
if (
(schema.fields[field].type && schema.fields[field].type === 'Pointer') ||
(schema.fields[field].type && schema.fields[field].type === 'Array')
) {
includeFields.push([field]);
keyFields.push(field);
}
Expand Down