Giter Site home page Giter Site logo

Comments (1)

thisisgit avatar thisisgit commented on July 4, 2024

I found where that validateWhere is located:

validateWhere() {
if (this._filters.length > 0) {
this._filterCheck(this._filters);
}
}
_filterCheck(filters) {
for (let i = 0; i < filters.length; i++) {
const filter = filters[i];
if (filter.queries) {
// Recursively check sub-queries for Filters
this._filterCheck(filter.queries);
// If it is a Filter query, skip the rest of the loop
continue;
}
// Skip if no inequality
if (!INEQUALITY[filter.operator]) {
continue;
}
if (filter.operator === OPERATORS['!=']) {
if (this.hasNotEqual) {
throw new Error("Invalid query. You cannot use more than one '!=' inequality filter.");
}
//needs to set hasNotEqual = true before setting first hasInequality = filter. It is used in a condition check later
this.hasNotEqual = true;
}
// Set the first inequality
if (!this.hasInequality) {
this.hasInequality = filter;
continue;
}
// Check the set value is the same as the new one
if (INEQUALITY[filter.operator] && this.hasInequality) {
if (this.hasInequality.fieldPath._toPath() !== filter.fieldPath._toPath()) {
throw new Error(
`Invalid query. All where filters with an inequality (<, <=, >, != or >=) must be on the same field. But you have inequality filters on '${this.hasInequality.fieldPath._toPath()}' and '${filter.fieldPath._toPath()}'`,
);
}
}
}
for (let i = 0; i < filters.length; i++) {
const filter = filters[i];
if (filter.operator === OPERATORS['array-contains']) {
if (this.hasArrayContains) {
throw new Error('Invalid query. Queries only support a single array-contains filter.');
}
this.hasArrayContains = true;
}
if (filter.operator === OPERATORS['array-contains-any']) {
if (this.hasArrayContainsAny) {
throw new Error(
"Invalid query. You cannot use more than one 'array-contains-any' filter.",
);
}
if (this.hasNotIn) {
throw new Error(
"Invalid query. You cannot use 'array-contains-any' filters with 'not-in' filters.",
);
}
this.hasArrayContainsAny = true;
}
if (filter.operator === OPERATORS.in) {
if (this.hasNotIn) {
throw new Error("Invalid query. You cannot use 'in' filters with 'not-in' filters.");
}
this.hasIn = true;
}
if (filter.operator === OPERATORS['not-in']) {
if (this.hasNotIn) {
throw new Error("Invalid query. You cannot use more than one 'not-in' filter.");
}
if (this.hasNotEqual) {
throw new Error(
"Invalid query. You cannot use 'not-in' filters with '!=' inequality filters",
);
}
if (this.hasIn) {
throw new Error("Invalid query. You cannot use 'not-in' filters with 'in' filters.");
}
if (this.hasArrayContainsAny) {
throw new Error(
"Invalid query. You cannot use 'not-in' filters with 'array-contains-any' filters.",
);
}
this.hasNotIn = true;
}
}
}

So what it does is to recursively call _filterCheck function, and the first for loop of the function is responsible for checking inequality filter for multiple fields.
I believe that for loop can now be removed since it's now supported.

I wanted to open a PR for this but for some reason, it returns 403 whenever I try to push working branch to remote as described here.

from react-native-firebase.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.