Skip to content

Commit 3ed3982

Browse files
committed
Fixes bug affecting matchesQuery and doesNotMatchQuery on relations on unfetched objects
1 parent e00112e commit 3ed3982

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

spec/ParseRelation.spec.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
'use strict';
12
// This is a port of the test suite:
23
// hungry/js/test/parse_relation_test.js
34

@@ -501,7 +502,7 @@ describe('Parse.Relation testing', () => {
501502
});
502503
});
503504

504-
notWorking('should properly get related objects with unfetched queries', (done) => {
505+
it('should properly get related objects with unfetched queries', (done) => {
505506
let objects = [];
506507
let owners = [];
507508
let allObjects = [];
@@ -544,7 +545,30 @@ describe('Parse.Relation testing', () => {
544545
return query.find();
545546
}).then((results) => {
546547
expect(results.length).toBe(5);
548+
results.forEach((result) => {
549+
expect(result.get('key').get('even')).toBe(true);
550+
});
551+
return Promise.resolve();
552+
}).then(() => {
553+
console.log('');
554+
// Query on the relation of another owner
555+
let object = new Parse.Object('AnotherOwner');
556+
object.id = anotherOwner.id;
557+
let relationQuery = object.relation('relationKey').query();
558+
// Just get the even ones
559+
relationQuery.equalTo('even', true);
560+
// Make the query on anOwner
561+
let query = new Parse.Query('AnOwner');
562+
// where key match the relation query.
563+
query.doesNotMatchQuery('key', relationQuery);
564+
query.include('key');
565+
return query.find();
566+
}).then((results) => {
567+
expect(results.length).toBe(5);
568+
results.forEach((result) => {
569+
expect(result.get('key').get('even')).toBe(false);
570+
});
547571
done();
548-
});
572+
})
549573
});
550574
});

src/RestQuery.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ function RestQuery(config, auth, className, restWhere = {}, restOptions = {}) {
2020
this.className = className;
2121
this.restWhere = restWhere;
2222
this.response = null;
23-
2423
this.findOptions = {};
2524
if (!this.auth.isMaster) {
2625
this.findOptions.acl = this.auth.user ? [this.auth.user.id] : null;
@@ -205,15 +204,19 @@ RestQuery.prototype.replaceInQuery = function() {
205204
'improper usage of $inQuery');
206205
}
207206

207+
let additionalOptions = {
208+
redirectClassNameForKey: inQueryValue.redirectClassNameForKey
209+
};
210+
208211
var subquery = new RestQuery(
209212
this.config, this.auth, inQueryValue.className,
210-
inQueryValue.where);
213+
inQueryValue.where, additionalOptions);
211214
return subquery.execute().then((response) => {
212215
var values = [];
213216
for (var result of response.results) {
214217
values.push({
215218
__type: 'Pointer',
216-
className: inQueryValue.className,
219+
className: subquery.className,
217220
objectId: result.objectId
218221
});
219222
}
@@ -223,7 +226,6 @@ RestQuery.prototype.replaceInQuery = function() {
223226
} else {
224227
inQueryObject['$in'] = values;
225228
}
226-
227229
// Recurse to repeat
228230
return this.replaceInQuery();
229231
});
@@ -246,15 +248,19 @@ RestQuery.prototype.replaceNotInQuery = function() {
246248
'improper usage of $notInQuery');
247249
}
248250

251+
let additionalOptions = {
252+
redirectClassNameForKey: notInQueryValue.redirectClassNameForKey
253+
};
254+
249255
var subquery = new RestQuery(
250256
this.config, this.auth, notInQueryValue.className,
251-
notInQueryValue.where);
257+
notInQueryValue.where, additionalOptions);
252258
return subquery.execute().then((response) => {
253259
var values = [];
254260
for (var result of response.results) {
255261
values.push({
256262
__type: 'Pointer',
257-
className: notInQueryValue.className,
263+
className: subquery.className,
258264
objectId: result.objectId
259265
});
260266
}
@@ -385,7 +391,6 @@ RestQuery.prototype.runFind = function() {
385391
r.className = this.redirectClassName;
386392
}
387393
}
388-
389394
this.response = {results: results};
390395
});
391396
};
@@ -423,7 +428,7 @@ RestQuery.prototype.handleInclude = function() {
423428
this.include = this.include.slice(1);
424429
return this.handleInclude();
425430
}
426-
431+
427432
return pathResponse;
428433
};
429434

0 commit comments

Comments
 (0)