Skip to content

Commit

Permalink
Fixes bug affecting matchesQuery and doesNotMatchQuery on relations o…
Browse files Browse the repository at this point in the history
…n unfetched objects
  • Loading branch information
flovilmart committed Mar 15, 2016
1 parent e00112e commit 5d886f0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
27 changes: 25 additions & 2 deletions spec/ParseRelation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,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 owners = [];
let allObjects = [];
Expand Down Expand Up @@ -544,7 +544,30 @@ describe('Parse.Relation testing', () => {
return query.find();
}).then((results) => {
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();
});
})
});
});
21 changes: 13 additions & 8 deletions src/RestQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ function RestQuery(config, auth, className, restWhere = {}, restOptions = {}) {
this.className = className;
this.restWhere = restWhere;
this.response = null;

this.findOptions = {};
if (!this.auth.isMaster) {
this.findOptions.acl = this.auth.user ? [this.auth.user.id] : null;
Expand Down Expand Up @@ -205,15 +204,19 @@ RestQuery.prototype.replaceInQuery = function() {
'improper usage of $inQuery');
}

let additionalOptions = {
redirectClassNameForKey: inQueryValue.redirectClassNameForKey
};

var subquery = new RestQuery(
this.config, this.auth, inQueryValue.className,
inQueryValue.where);
inQueryValue.where, additionalOptions);
return subquery.execute().then((response) => {
var values = [];
for (var result of response.results) {
values.push({
__type: 'Pointer',
className: inQueryValue.className,
className: subquery.className,
objectId: result.objectId
});
}
Expand All @@ -223,7 +226,6 @@ RestQuery.prototype.replaceInQuery = function() {
} else {
inQueryObject['$in'] = values;
}

// Recurse to repeat
return this.replaceInQuery();
});
Expand All @@ -246,15 +248,19 @@ RestQuery.prototype.replaceNotInQuery = function() {
'improper usage of $notInQuery');
}

let additionalOptions = {
redirectClassNameForKey: notInQueryValue.redirectClassNameForKey
};

var subquery = new RestQuery(
this.config, this.auth, notInQueryValue.className,
notInQueryValue.where);
notInQueryValue.where, additionalOptions);
return subquery.execute().then((response) => {
var values = [];
for (var result of response.results) {
values.push({
__type: 'Pointer',
className: notInQueryValue.className,
className: subquery.className,
objectId: result.objectId
});
}
Expand Down Expand Up @@ -385,7 +391,6 @@ RestQuery.prototype.runFind = function() {
r.className = this.redirectClassName;
}
}

this.response = {results: results};
});
};
Expand Down Expand Up @@ -423,7 +428,7 @@ RestQuery.prototype.handleInclude = function() {
this.include = this.include.slice(1);
return this.handleInclude();
}

return pathResponse;
};

Expand Down

0 comments on commit 5d886f0

Please sign in to comment.