PG: Fix containedIn query on empty array (#5254)
* PG: Fix containedIn query on empty array * improve logic
This commit is contained in:
@@ -238,6 +238,30 @@ describe('Parse.Query testing', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('query notContainedIn on empty array', async () => {
|
||||
const object = new TestObject();
|
||||
object.set('value', 100);
|
||||
await object.save();
|
||||
|
||||
const query = new Parse.Query(TestObject);
|
||||
query.notContainedIn('value', []);
|
||||
|
||||
const results = await query.find();
|
||||
equal(results.length, 1);
|
||||
});
|
||||
|
||||
it('query containedIn on empty array', async () => {
|
||||
const object = new TestObject();
|
||||
object.set('value', 100);
|
||||
await object.save();
|
||||
|
||||
const query = new Parse.Query(TestObject);
|
||||
query.containedIn('value', []);
|
||||
|
||||
const results = await query.find();
|
||||
equal(results.length, 0);
|
||||
});
|
||||
|
||||
it('query with limit', function(done) {
|
||||
const baz = new TestObject({ foo: 'baz' });
|
||||
const qux = new TestObject({ foo: 'qux' });
|
||||
|
||||
@@ -402,8 +402,8 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => {
|
||||
index = index + 1 + inPatterns.length;
|
||||
} else if (isInOrNin) {
|
||||
var createConstraint = (baseArray, notIn) => {
|
||||
const not = notIn ? ' NOT ' : '';
|
||||
if (baseArray.length > 0) {
|
||||
const not = notIn ? ' NOT ' : '';
|
||||
if (isArrayField) {
|
||||
patterns.push(
|
||||
`${not} array_contains($${index}:name, $${index + 1})`
|
||||
@@ -430,6 +430,13 @@ const buildWhereClause = ({ schema, query, index }): WhereClause => {
|
||||
values.push(fieldName);
|
||||
patterns.push(`$${index}:name IS NULL`);
|
||||
index = index + 1;
|
||||
} else {
|
||||
// Handle empty array
|
||||
if (notIn) {
|
||||
patterns.push('1 = 1'); // Return all values
|
||||
} else {
|
||||
patterns.push('1 = 2'); // Return no values
|
||||
}
|
||||
}
|
||||
};
|
||||
if (fieldValue.$in) {
|
||||
|
||||
Reference in New Issue
Block a user