mergeDocumentJson function

Map<String, dynamic> mergeDocumentJson(
  1. DocumentDto document
)

Flattens a document into the shape a Model's fromJson expects.

The system fields are written last and so win any collision: a collection that stores its own id must not end up with a model pointing at the wrong document, which save() would then write back to.

Implementation

Map<String, dynamic> mergeDocumentJson(DocumentDto document) {
  return {
    ...document.data,
    'id': document.id,
    'createdAt': document.createdAt.toIso8601String(),
    'updatedAt': document.updatedAt.toIso8601String(),
  };
}