Skip to content

Commit

Permalink
feat: cvColl.addMap
Browse files Browse the repository at this point in the history
  • Loading branch information
alextekartik committed Oct 4, 2024
1 parent ad6b3d2 commit c21e911
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app_cv_firestore/lib/src/v2/cv_collection_reference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class CvCollectionReference<T extends CvFirestoreDocument>
Future<T> add(Firestore firestore, T document) =>
firestore.collection(path).cvAdd(document);

/// Add a map
Future<CvDocumentReference<T>> addMap(Firestore firestore, Model data) async {
var rawRef = await raw(firestore).add(data);
return CvDocumentReference<T>(rawRef.path);
}

/// Raw document reference
CollectionReference raw(Firestore firestore) => firestore.collection(path);

Expand Down
3 changes: 3 additions & 0 deletions app_cv_firestore/test/app_cv_firestore_v2_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ void main() {
// Create a new record
doc = await collection.add(firestore, doc);
expect(doc.id, isNot('1'));
var ref = await collection.addMap(firestore, doc.toMap());
expect(ref.id, isNot('1'));
expect(ref.id, isNot(doc.id));
});
test('collection.cast', () async {
var collectionOther = CvCollectionReference<CvFsEmpty>('test');
Expand Down

0 comments on commit c21e911

Please sign in to comment.