Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/cloud_firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.12.6

* Support for `orderBy` on map fields (e.g. `orderBy('cake.flavor')`) for
`startAtDocument`, `startAfterDocument`, `endAtDocument`, and `endBeforeDocument` added.

## 0.12.5+2

* Automatically use version from pubspec.yaml when reporting usage to Firebase.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,16 @@ private Object[] getDocumentValues(
if (orderBy != null) {
for (List<Object> order : orderBy) {
String orderByFieldName = (String) order.get(0);
data.add(documentData.get(orderByFieldName));
if (orderByFieldName.contains(".")) {
String[] fieldNameParts = orderByFieldName.split("\\.");
Map<String, Object> current = (Map<String, Object>) documentData.get(fieldNameParts[0]);
for (int i = 1; i < fieldNameParts.length - 1; i++) {
current = (Map<String, Object>) current.get(fieldNameParts[i]);
}
data.add(current.get(fieldNameParts[fieldNameParts.length - 1]));
} else {
data.add(documentData.get(orderByFieldName));
}
}
}
data.add((boolean) arguments.get("isCollectionGroup") ? document.get("path") : documentId);
Expand Down
39 changes: 39 additions & 0 deletions packages/cloud_firestore/example/test_driver/cloud_firestore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,44 @@ void main() {
await doc1.delete();
await doc2.delete();
});

test('pagination with map', () async {
// Populate the database with two test documents.
final CollectionReference messages = firestore.collection('messages');
final DocumentReference doc1 = messages.document();
// Use document ID as a unique identifier to ensure that we don't
// collide with other tests running against this database.
final String testRun = doc1.documentID;
await doc1.setData(<String, dynamic>{
'cake': <String, dynamic>{
'flavor': <String, dynamic>{'type': 1, 'test_run': testRun}
}
});

final DocumentSnapshot snapshot1 = await doc1.get();
final DocumentReference doc2 = await messages.add(<String, dynamic>{
'cake': <String, dynamic>{
'flavor': <String, dynamic>{'type': 2, 'test_run': testRun}
}
});

QuerySnapshot snapshot;
List<DocumentSnapshot> results;

// One pagination call is enough as all of the pagination methods use the same method to get data internally.
snapshot = await messages
.orderBy('cake.flavor.type')
.where('cake.flavor.test_run', isEqualTo: testRun)
.startAtDocument(snapshot1)
.getDocuments();
results = snapshot.documents;

expect(results.length, 2);
expect(results[0].data['cake']['flavor']['type'], 1);
expect(results[1].data['cake']['flavor']['type'], 2);

await doc1.delete();
await doc2.delete();
});
});
}
12 changes: 11 additions & 1 deletion packages/cloud_firestore/ios/Classes/CloudFirestorePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@
for (id item in orderBy) {
NSArray *orderByParameters = item;
NSString *fieldName = orderByParameters[0];
[values addObject:[documentData objectForKey:fieldName]];
if ([fieldName rangeOfString:@"."].location != NSNotFound) {
NSArray *fieldNameParts = [fieldName componentsSeparatedByString:@"."];
NSDictionary *currentMap = [documentData objectForKey:[fieldNameParts objectAtIndex:0]];
for (int i = 1; i < [fieldNameParts count] - 1; i++) {
currentMap = [currentMap objectForKey:[fieldNameParts objectAtIndex:i]];
}
[values addObject:[currentMap objectForKey:[fieldNameParts
objectAtIndex:[fieldNameParts count] - 1]]];
} else {
[values addObject:[documentData objectForKey:fieldName]];
}
}
}
if (isCollectionGroup) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cloud_firestore/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for Cloud Firestore, a cloud-hosted, noSQL database
live synchronization and offline support on Android and iOS.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/cloud_firestore
version: 0.12.5+2
version: 0.12.6

flutter:
plugin:
Expand Down