aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source
diff options
context:
space:
mode:
authorGravatar Sebastian Schmidt <mrschmidt@google.com>2018-06-07 13:57:01 -0700
committerGravatar GitHub <noreply@github.com>2018-06-07 13:57:01 -0700
commitd13a51abace9e1510ae953079f98e7b1390b128b (patch)
treece7fb57b7cdde1c893491e5106217a5e9e5482d2 /Firestore/Source
parent7b2aa01da3df89dbea23b7c73202c6bf3f5813d3 (diff)
Allowing field deletes using merge fields (#1389)
Diffstat (limited to 'Firestore/Source')
-rw-r--r--Firestore/Source/API/FSTUserDataConverter.mm22
1 files changed, 21 insertions, 1 deletions
diff --git a/Firestore/Source/API/FSTUserDataConverter.mm b/Firestore/Source/API/FSTUserDataConverter.mm
index d73a870..d3e339d 100644
--- a/Firestore/Source/API/FSTUserDataConverter.mm
+++ b/Firestore/Source/API/FSTUserDataConverter.mm
@@ -218,6 +218,9 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) {
/** Returns true for the non-query parse contexts (Set, MergeSet and Update) */
- (BOOL)isWrite;
+/** Returns 'YES' if 'fieldPath' was traversed when creating this context. */
+- (BOOL)containsFieldPath:(const FieldPath &)fieldPath;
+
- (const FieldPath *)path;
- (const std::vector<FieldPath> *)fieldMask;
@@ -331,6 +334,22 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) {
}
}
+- (BOOL)containsFieldPath:(const FieldPath &)fieldPath {
+ for (const FieldPath &field : *_fieldMask) {
+ if (fieldPath.IsPrefixOf(field)) {
+ return YES;
+ }
+ }
+
+ for (const FieldTransform &fieldTransform : *_fieldTransforms) {
+ if (fieldPath.IsPrefixOf(fieldTransform.path())) {
+ return YES;
+ }
+ }
+
+ return NO;
+}
+
- (void)validatePath {
// TODO(b/34871131): Remove nil check once we have proper paths for fields within arrays.
if (_path == nullptr) {
@@ -444,7 +463,8 @@ typedef NS_ENUM(NSInteger, FSTUserDataSource) {
@"All elements in mergeFields: must be NSStrings or FIRFieldPaths.");
}
- if ([updateData valueForPath:path] == nil) {
+ // Verify that all elements specified in the field mask are part of the parsed context.
+ if (![context containsFieldPath:path]) {
FSTThrowInvalidArgument(
@"Field '%s' is specified in your field mask but missing from your input data.",
path.CanonicalString().c_str());