Skip to content

Commit 5d886f0

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

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

spec/ParseRelation.spec.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ describe('Parse.Relation testing', () => {
501501
});
502502
});
503503

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

src/RestQuery.js

+13-8
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)