aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source
diff options
context:
space:
mode:
authorGravatar Michael Lehenbauer <mikelehen@gmail.com>2018-05-16 17:05:33 -0700
committerGravatar GitHub <noreply@github.com>2018-05-16 17:05:33 -0700
commit0ec836f9ca71b27fa54a11ae9e07e60b8c5cc002 (patch)
treeb677f04b8659299146b661dded71e4860fe956f0 /Firestore/Source
parentdd83f4e30bed1b5caf5cc862e74743c84ca6e450 (diff)
b/79432277: Limit Queries to only a single array-contains clause. (#1286)
Diffstat (limited to 'Firestore/Source')
-rw-r--r--Firestore/Source/API/FIRQuery+Internal.h4
-rw-r--r--Firestore/Source/API/FIRQuery.mm5
-rw-r--r--Firestore/Source/Core/FSTQuery.h3
-rw-r--r--Firestore/Source/Core/FSTQuery.mm10
4 files changed, 22 insertions, 0 deletions
diff --git a/Firestore/Source/API/FIRQuery+Internal.h b/Firestore/Source/API/FIRQuery+Internal.h
index c4f9f23..e207837 100644
--- a/Firestore/Source/API/FIRQuery+Internal.h
+++ b/Firestore/Source/API/FIRQuery+Internal.h
@@ -35,6 +35,8 @@ NS_ASSUME_NONNULL_BEGIN
* Creates and returns a new `FIRQuery` with the additional filter that documents must contain
* the specified field, it must be an array, and the array must contain the provided value.
*
+ * A query can have only one arrayContains filter.
+ *
* @param field The name of the field containing an array to search
* @param value The value that must be contained in the array
*
@@ -49,6 +51,8 @@ NS_ASSUME_NONNULL_BEGIN
* Creates and returns a new `FIRQuery` with the additional filter that documents must contain
* the specified field, it must be an array, and the array must contain the provided value.
*
+ * A query can have only one arrayContains filter.
+ *
* @param path The path of the field containing an array to search
* @param value The value that must be contained in the array
*
diff --git a/Firestore/Source/API/FIRQuery.mm b/Firestore/Source/API/FIRQuery.mm
index 596f6ac..ad4d2aa 100644
--- a/Firestore/Source/API/FIRQuery.mm
+++ b/Firestore/Source/API/FIRQuery.mm
@@ -527,6 +527,11 @@ addSnapshotListenerInternalWithOptions:(FSTListenOptions *)internalOptions
if (firstOrderByField) {
[self validateOrderByField:*firstOrderByField matchesInequalityField:filter.field];
}
+ } else if (filter.filterOperator == FSTRelationFilterOperatorArrayContains) {
+ if ([self.query hasArrayContainsFilter]) {
+ FSTThrowInvalidUsage(@"InvalidQueryException",
+ @"Invalid Query. Queries only support a single arrayContains filter.");
+ }
}
}
diff --git a/Firestore/Source/Core/FSTQuery.h b/Firestore/Source/Core/FSTQuery.h
index 572fabb..e38d3dd 100644
--- a/Firestore/Source/Core/FSTQuery.h
+++ b/Firestore/Source/Core/FSTQuery.h
@@ -245,6 +245,9 @@ typedef NS_ENUM(NSInteger, FSTRelationFilterOperator) {
*/
- (const firebase::firestore::model::FieldPath *)inequalityFilterField;
+/** Returns YES if the query has an arrayContains filter already. */
+- (BOOL)hasArrayContainsFilter;
+
/** Returns the first field in an order-by constraint, or nullptr if none. */
- (const firebase::firestore::model::FieldPath *)firstSortOrderField;
diff --git a/Firestore/Source/Core/FSTQuery.mm b/Firestore/Source/Core/FSTQuery.mm
index d3961e8..13ebadb 100644
--- a/Firestore/Source/Core/FSTQuery.mm
+++ b/Firestore/Source/Core/FSTQuery.mm
@@ -724,6 +724,16 @@ NSString *FSTStringFromQueryRelationOperator(FSTRelationFilterOperator filterOpe
return nullptr;
}
+- (BOOL)hasArrayContainsFilter {
+ for (id<FSTFilter> filter in self.filters) {
+ if ([filter isKindOfClass:[FSTRelationFilter class]] &&
+ ((FSTRelationFilter *)filter).filterOperator == FSTRelationFilterOperatorArrayContains) {
+ return YES;
+ }
+ }
+ return NO;
+}
+
- (const FieldPath *)firstSortOrderField {
if (self.explicitSortOrders.count > 0) {
return &self.explicitSortOrders.firstObject.field;