lmcq / firebase-firestorm

Firebase Firestorm is an ORM for Firestore which can be used with Typescript.
MIT License
252 stars 19 forks source link

Nullable Fields #8

Open richartkeil opened 4 years ago

richartkeil commented 4 years ago

Does the ORM currently deal with nullable fields? In my case I have a collection of documents that have a deletedAt field. This field can either be null or a timestamp (corresponding to if the document is deleted or not).

When I try to get the documents of this collection and call .toData() I receive the following exception:

TypeError: Cannot read property 'toDate' of undefined
    at /…/node_modules/firebase-firestorm/lib/decorators/timestamp.js:52:88
    at Function.FieldUtils.process (/…/node_modules/firebase-firestorm/lib/utils/FieldUtils.js:67:20)
    at toData (/…node_modules/firebase-firestorm/lib/decorators/timestamp.js:52:33)
    at Object.field.toData (/…/node_modules/firebase-firestorm/lib/decorators/timestamp.js:72:20)
    at /…/node_modules/firebase-firestorm/lib/Entity.js:20:39
    at Map.forEach (<anonymous>)
    at MyModel.Entity.toData (/…/node_modules/firebase-firestorm/lib/Entity.js:18:16)

It would be great to know if this is expected behaviour. Same concerning fields that are defined on the model but do not exist on the document (if so, this would mean potentially writing migrations in the future).

davidassigbi commented 4 years ago

Hi @richartkeil. I'm having the same issue and i would like to know if you have finally found a solution or workaround ?