fixes same bug affecting $select and $dontSelect
This commit is contained in:
@@ -550,7 +550,6 @@ describe('Parse.Relation testing', () => {
|
||||
});
|
||||
return Promise.resolve();
|
||||
}).then(() => {
|
||||
console.log('');
|
||||
// Query on the relation of another owner
|
||||
let object = new Parse.Object('AnotherOwner');
|
||||
object.id = anotherOwner.id;
|
||||
@@ -571,4 +570,86 @@ describe('Parse.Relation testing', () => {
|
||||
done();
|
||||
})
|
||||
});
|
||||
|
||||
it("select query", function(done) {
|
||||
var RestaurantObject = Parse.Object.extend("Restaurant");
|
||||
var PersonObject = Parse.Object.extend("Person");
|
||||
var OwnerObject = Parse.Object.extend('Owner');
|
||||
var restaurants = [
|
||||
new RestaurantObject({ ratings: 5, location: "Djibouti" }),
|
||||
new RestaurantObject({ ratings: 3, location: "Ouagadougou" }),
|
||||
];
|
||||
let persons = [
|
||||
new PersonObject({ name: "Bob", hometown: "Djibouti" }),
|
||||
new PersonObject({ name: "Tom", hometown: "Ouagadougou" }),
|
||||
new PersonObject({ name: "Billy", hometown: "Detroit" }),
|
||||
];
|
||||
let owner = new OwnerObject({name: 'Joe'});
|
||||
let ownerId;
|
||||
let allObjects = [owner].concat(restaurants).concat(persons);
|
||||
expect(allObjects.length).toEqual(6);
|
||||
Parse.Object.saveAll([owner].concat(restaurants).concat(persons)).then(function() {
|
||||
ownerId = owner.id;
|
||||
owner.relation('restaurants').add(restaurants);
|
||||
return owner.save()
|
||||
}).then(() => {
|
||||
let unfetchedOwner = new OwnerObject();
|
||||
unfetchedOwner.id = owner.id;
|
||||
var query = unfetchedOwner.relation('restaurants').query();
|
||||
query.greaterThan("ratings", 4);
|
||||
var mainQuery = new Parse.Query(PersonObject);
|
||||
mainQuery.matchesKeyInQuery("hometown", "location", query);
|
||||
mainQuery.find(expectSuccess({
|
||||
success: function(results) {
|
||||
equal(results.length, 1);
|
||||
if (results.length > 0) {
|
||||
equal(results[0].get('name'), 'Bob');
|
||||
}
|
||||
done();
|
||||
}
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
it("dontSelect query", function(done) {
|
||||
var RestaurantObject = Parse.Object.extend("Restaurant");
|
||||
var PersonObject = Parse.Object.extend("Person");
|
||||
var OwnerObject = Parse.Object.extend('Owner');
|
||||
var restaurants = [
|
||||
new RestaurantObject({ ratings: 5, location: "Djibouti" }),
|
||||
new RestaurantObject({ ratings: 3, location: "Ouagadougou" }),
|
||||
];
|
||||
let persons = [
|
||||
new PersonObject({ name: "Bob", hometown: "Djibouti" }),
|
||||
new PersonObject({ name: "Tom", hometown: "Ouagadougou" }),
|
||||
new PersonObject({ name: "Billy", hometown: "Detroit" }),
|
||||
];
|
||||
let owner = new OwnerObject({name: 'Joe'});
|
||||
let ownerId;
|
||||
let allObjects = [owner].concat(restaurants).concat(persons);
|
||||
expect(allObjects.length).toEqual(6);
|
||||
Parse.Object.saveAll([owner].concat(restaurants).concat(persons)).then(function() {
|
||||
ownerId = owner.id;
|
||||
owner.relation('restaurants').add(restaurants);
|
||||
return owner.save()
|
||||
}).then(() => {
|
||||
let unfetchedOwner = new OwnerObject();
|
||||
unfetchedOwner.id = owner.id;
|
||||
var query = unfetchedOwner.relation('restaurants').query();
|
||||
query.greaterThan("ratings", 4);
|
||||
var mainQuery = new Parse.Query(PersonObject);
|
||||
mainQuery.doesNotMatchKeyInQuery("hometown", "location", query);
|
||||
mainQuery.ascending('name');
|
||||
mainQuery.find(expectSuccess({
|
||||
success: function(results) {
|
||||
equal(results.length, 2);
|
||||
if (results.length > 0) {
|
||||
equal(results[0].get('name'), 'Billy');
|
||||
equal(results[1].get('name'), 'Tom');
|
||||
}
|
||||
done();
|
||||
}
|
||||
}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -299,9 +299,13 @@ RestQuery.prototype.replaceSelect = function() {
|
||||
'improper usage of $select');
|
||||
}
|
||||
|
||||
let additionalOptions = {
|
||||
redirectClassNameForKey: selectValue.query.redirectClassNameForKey
|
||||
};
|
||||
|
||||
var subquery = new RestQuery(
|
||||
this.config, this.auth, selectValue.query.className,
|
||||
selectValue.query.where);
|
||||
selectValue.query.where, additionalOptions);
|
||||
return subquery.execute().then((response) => {
|
||||
var values = [];
|
||||
for (var result of response.results) {
|
||||
@@ -340,9 +344,13 @@ RestQuery.prototype.replaceDontSelect = function() {
|
||||
throw new Parse.Error(Parse.Error.INVALID_QUERY,
|
||||
'improper usage of $dontSelect');
|
||||
}
|
||||
let additionalOptions = {
|
||||
redirectClassNameForKey: dontSelectValue.query.redirectClassNameForKey
|
||||
};
|
||||
|
||||
var subquery = new RestQuery(
|
||||
this.config, this.auth, dontSelectValue.query.className,
|
||||
dontSelectValue.query.where);
|
||||
dontSelectValue.query.where, additionalOptions);
|
||||
return subquery.execute().then((response) => {
|
||||
var values = [];
|
||||
for (var result of response.results) {
|
||||
|
||||
Reference in New Issue
Block a user