Fixes bug affecting matchesQuery and doesNotMatchQuery on relations on unfetched objects

This commit is contained in:
Florent Vilmart
2016-03-15 16:19:12 -04:00
parent e00112ec3c
commit 3ed3982e0e
2 changed files with 39 additions and 10 deletions

View File

@@ -1,3 +1,4 @@
'use strict';
// This is a port of the test suite: // This is a port of the test suite:
// hungry/js/test/parse_relation_test.js // hungry/js/test/parse_relation_test.js
@@ -501,7 +502,7 @@ describe('Parse.Relation testing', () => {
}); });
}); });
notWorking('should properly get related objects with unfetched queries', (done) => { it('should properly get related objects with unfetched queries', (done) => {
let objects = []; let objects = [];
let owners = []; let owners = [];
let allObjects = []; let allObjects = [];
@@ -544,7 +545,30 @@ describe('Parse.Relation testing', () => {
return query.find(); return query.find();
}).then((results) => { }).then((results) => {
expect(results.length).toBe(5); expect(results.length).toBe(5);
results.forEach((result) => {
expect(result.get('key').get('even')).toBe(true);
});
return Promise.resolve();
}).then(() => {
console.log('');
// Query on the relation of another owner
let object = new Parse.Object('AnotherOwner');
object.id = anotherOwner.id;
let relationQuery = object.relation('relationKey').query();
// Just get the even ones
relationQuery.equalTo('even', true);
// Make the query on anOwner
let query = new Parse.Query('AnOwner');
// where key match the relation query.
query.doesNotMatchQuery('key', relationQuery);
query.include('key');
return query.find();
}).then((results) => {
expect(results.length).toBe(5);
results.forEach((result) => {
expect(result.get('key').get('even')).toBe(false);
});
done(); done();
}); })
}); });
}); });

View File

@@ -20,7 +20,6 @@ function RestQuery(config, auth, className, restWhere = {}, restOptions = {}) {
this.className = className; this.className = className;
this.restWhere = restWhere; this.restWhere = restWhere;
this.response = null; this.response = null;
this.findOptions = {}; this.findOptions = {};
if (!this.auth.isMaster) { if (!this.auth.isMaster) {
this.findOptions.acl = this.auth.user ? [this.auth.user.id] : null; this.findOptions.acl = this.auth.user ? [this.auth.user.id] : null;
@@ -205,15 +204,19 @@ RestQuery.prototype.replaceInQuery = function() {
'improper usage of $inQuery'); 'improper usage of $inQuery');
} }
let additionalOptions = {
redirectClassNameForKey: inQueryValue.redirectClassNameForKey
};
var subquery = new RestQuery( var subquery = new RestQuery(
this.config, this.auth, inQueryValue.className, this.config, this.auth, inQueryValue.className,
inQueryValue.where); inQueryValue.where, additionalOptions);
return subquery.execute().then((response) => { return subquery.execute().then((response) => {
var values = []; var values = [];
for (var result of response.results) { for (var result of response.results) {
values.push({ values.push({
__type: 'Pointer', __type: 'Pointer',
className: inQueryValue.className, className: subquery.className,
objectId: result.objectId objectId: result.objectId
}); });
} }
@@ -223,7 +226,6 @@ RestQuery.prototype.replaceInQuery = function() {
} else { } else {
inQueryObject['$in'] = values; inQueryObject['$in'] = values;
} }
// Recurse to repeat // Recurse to repeat
return this.replaceInQuery(); return this.replaceInQuery();
}); });
@@ -246,15 +248,19 @@ RestQuery.prototype.replaceNotInQuery = function() {
'improper usage of $notInQuery'); 'improper usage of $notInQuery');
} }
let additionalOptions = {
redirectClassNameForKey: notInQueryValue.redirectClassNameForKey
};
var subquery = new RestQuery( var subquery = new RestQuery(
this.config, this.auth, notInQueryValue.className, this.config, this.auth, notInQueryValue.className,
notInQueryValue.where); notInQueryValue.where, additionalOptions);
return subquery.execute().then((response) => { return subquery.execute().then((response) => {
var values = []; var values = [];
for (var result of response.results) { for (var result of response.results) {
values.push({ values.push({
__type: 'Pointer', __type: 'Pointer',
className: notInQueryValue.className, className: subquery.className,
objectId: result.objectId objectId: result.objectId
}); });
} }
@@ -385,7 +391,6 @@ RestQuery.prototype.runFind = function() {
r.className = this.redirectClassName; r.className = this.redirectClassName;
} }
} }
this.response = {results: results}; this.response = {results: results};
}); });
}; };
@@ -423,7 +428,7 @@ RestQuery.prototype.handleInclude = function() {
this.include = this.include.slice(1); this.include = this.include.slice(1);
return this.handleInclude(); return this.handleInclude();
} }
return pathResponse; return pathResponse;
}; };