Do not require where clause in condition on queries.

This commit is contained in:
Nikita Lutsenko
2016-03-08 17:08:07 -08:00
parent 3723b9bb75
commit e93873f7b1
2 changed files with 36 additions and 12 deletions

View File

@@ -2,6 +2,9 @@
// hungry/js/test/parse_query_test.js // hungry/js/test/parse_query_test.js
// //
// Some new tests are added. // Some new tests are added.
'use strict';
const Parse = require('parse/node');
describe('Parse.Query testing', () => { describe('Parse.Query testing', () => {
it("basic query", function(done) { it("basic query", function(done) {
@@ -1574,6 +1577,29 @@ describe('Parse.Query testing', () => {
}); });
}); });
it("dontSelect query without conditions", function(done) {
const RestaurantObject = Parse.Object.extend("Restaurant");
const PersonObject = Parse.Object.extend("Person");
const objects = [
new RestaurantObject({ location: "Djibouti" }),
new RestaurantObject({ location: "Ouagadougou" }),
new PersonObject({ name: "Bob", hometown: "Djibouti" }),
new PersonObject({ name: "Tom", hometown: "Yoloblahblahblah" }),
new PersonObject({ name: "Billy", hometown: "Ouagadougou" })
];
Parse.Object.saveAll(objects, function() {
const query = new Parse.Query(RestaurantObject);
const mainQuery = new Parse.Query(PersonObject);
mainQuery.doesNotMatchKeyInQuery("hometown", "location", query);
mainQuery.find().then(results => {
equal(results.length, 1);
equal(results[0].get('name'), 'Tom');
done();
});
});
});
it("object with length", function(done) { it("object with length", function(done) {
var TestObject = Parse.Object.extend("TestObject"); var TestObject = Parse.Object.extend("TestObject");
var obj = new TestObject(); var obj = new TestObject();
@@ -2088,7 +2114,7 @@ describe('Parse.Query testing', () => {
console.log(error); console.log(error);
}); });
}); });
// #371 // #371
it('should properly interpret a query', (done) => { it('should properly interpret a query', (done) => {
var query = new Parse.Query("C1"); var query = new Parse.Query("C1");
@@ -2104,7 +2130,7 @@ describe('Parse.Query testing', () => {
done(); done();
}) })
}); });
it('should properly interpret a query', (done) => { it('should properly interpret a query', (done) => {
var user = new Parse.User(); var user = new Parse.User();
user.set("username", "foo"); user.set("username", "foo");
@@ -2112,22 +2138,22 @@ describe('Parse.Query testing', () => {
return user.save().then( (user) => { return user.save().then( (user) => {
var objIdQuery = new Parse.Query("_User").equalTo("objectId", user.id); var objIdQuery = new Parse.Query("_User").equalTo("objectId", user.id);
var blockedUserQuery = user.relation("blockedUsers").query(); var blockedUserQuery = user.relation("blockedUsers").query();
var aResponseQuery = new Parse.Query("MatchRelationshipActivityResponse"); var aResponseQuery = new Parse.Query("MatchRelationshipActivityResponse");
aResponseQuery.equalTo("userA", user); aResponseQuery.equalTo("userA", user);
aResponseQuery.equalTo("userAResponse", 1); aResponseQuery.equalTo("userAResponse", 1);
var bResponseQuery = new Parse.Query("MatchRelationshipActivityResponse"); var bResponseQuery = new Parse.Query("MatchRelationshipActivityResponse");
bResponseQuery.equalTo("userB", user); bResponseQuery.equalTo("userB", user);
bResponseQuery.equalTo("userBResponse", 1); bResponseQuery.equalTo("userBResponse", 1);
var matchOr = Parse.Query.or(aResponseQuery, bResponseQuery); var matchOr = Parse.Query.or(aResponseQuery, bResponseQuery);
var matchRelationshipA = new Parse.Query("_User"); var matchRelationshipA = new Parse.Query("_User");
matchRelationshipA.matchesKeyInQuery("objectId", "userAObjectId", matchOr); matchRelationshipA.matchesKeyInQuery("objectId", "userAObjectId", matchOr);
var matchRelationshipB = new Parse.Query("_User"); var matchRelationshipB = new Parse.Query("_User");
matchRelationshipB.matchesKeyInQuery("objectId", "userBObjectId", matchOr); matchRelationshipB.matchesKeyInQuery("objectId", "userBObjectId", matchOr);
var orQuery = Parse.Query.or(objIdQuery, blockedUserQuery, matchRelationshipA, matchRelationshipB); var orQuery = Parse.Query.or(objIdQuery, blockedUserQuery, matchRelationshipA, matchRelationshipB);
var query = new Parse.Query("_User"); var query = new Parse.Query("_User");
query.doesNotMatchQuery("objectId", orQuery); query.doesNotMatchQuery("objectId", orQuery);
@@ -2140,8 +2166,8 @@ describe('Parse.Query testing', () => {
fail("should not fail"); fail("should not fail");
done(); done();
}); });
}); });
}); });

View File

@@ -324,12 +324,10 @@ RestQuery.prototype.replaceDontSelect = function() {
!dontSelectValue.key || !dontSelectValue.key ||
typeof dontSelectValue.query !== 'object' || typeof dontSelectValue.query !== 'object' ||
!dontSelectValue.query.className || !dontSelectValue.query.className ||
!dontSelectValue.query.where ||
Object.keys(dontSelectValue).length !== 2) { Object.keys(dontSelectValue).length !== 2) {
throw new Parse.Error(Parse.Error.INVALID_QUERY, throw new Parse.Error(Parse.Error.INVALID_QUERY,
'improper usage of $dontSelect'); 'improper usage of $dontSelect');
} }
var subquery = new RestQuery( var subquery = new RestQuery(
this.config, this.auth, dontSelectValue.query.className, this.config, this.auth, dontSelectValue.query.className,
dontSelectValue.query.where); dontSelectValue.query.where);