documentFromObject method

DocumentReference<Map<String, dynamic>> documentFromObject(
  1. dynamic object, {
  2. String? subcollection,
})

Returns a reference to a document using an object.

Implementation

DocumentReference<Map<String, dynamic>> documentFromObject(dynamic object, { String? subcollection }) {
  if (object == null) {
    throw NullIDException("Cannot get document reference from null object");
  }
  final String? className = FS.classNames[object.runtimeType];
  if (className == null) {
    throw UnsupportedError('No class name found for type: ${object.runtimeType}. Consider re-generating Firestorm data classes.');
  }

  if (subcollection != null) {
    return FS.instance.collection(className).doc(subcollection).collection(subcollection).doc(object.id);
  }
  return FS.instance.collection(className).doc(object.id);
}