one<T> method

Future<Transaction> one<T>(
  1. T object, {
  2. String? subcollection,
})

Deletes a document from Firestore using an object.

Implementation

Future<Transaction> one<T>(T object, { String? subcollection }) async {
  final serializer = FS.serializers[object.runtimeType];
  if (serializer == null) {
    throw UnsupportedError('No serializer found for type: ${object.runtimeType}. Consider re-generating Firestorm data classes.');
  }
  final map = serializer(object);
  if (map["id"].isEmpty) {
    throw NullIDException(map);
  }
  DocumentReference ref = FS.instance.collection(object.runtimeType.toString()).doc(map["id"]);
  if (subcollection != null) {
    ref = FS.instance.collection(object.runtimeType.toString()).doc(subcollection).collection(subcollection).doc(map["id"]);
  }
  return _tx.delete(ref);
}