Fix includeAll for querying a Pointer and Pointer array (#7002)
* initial test * Add failing testcase * fix includeAll by considering array
This commit is contained in:
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user