Skip to content

Commit

Permalink
Fix includeAll for querying a Pointer and Pointer array (#7002)
Browse files Browse the repository at this point in the history
* initial test

* Add failing testcase

* fix includeAll by considering array
  • Loading branch information
cbaker6 authored Nov 11, 2020
1 parent b4ec63e commit 568c285
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
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

0 comments on commit 568c285

Please sign in to comment.