-
Notifications
You must be signed in to change notification settings - Fork 977
Closed
Labels
Description
[REQUIRED] Describe your environment
- Operating System version: Windows
- Browser version: Chrome (87.0.4280.141)
- Firebase SDK version: 9.1.0
- Firebase Product: firestore
[REQUIRED] Describe the problem
When trying to save the DocumentReference from the QueryDocumentSnapshot in the ModelConverter.fromFirestore function. The resulting document reference object is missing several fields.
Steps to reproduce:
See code below:
Relevant Code:
interface MyModel {
ref: firebase.firestore.DocumentReference;
}
const modelConverter = {
toFirestore: function (model: MyModel) {
return _.omit(model, "ref");
},
fromFirestore: function (
snapshot: firebase.firestore.QueryDocumentSnapshot
): MyModel {
const model = snapshot.data();
// Some kind of validation, etc.
model.ref = snapshot.ref;
return model as MyModel;
},
};
const modelDocumentRef = firebase.firestore()
.collection("/models")
.doc("some_id")
.withConverter(modelConverter);
modelDocumentRef.onSnapshot((snapshot) => {
const model = snapshot.data();
const modelSubcollectionRef = model?.ref.collection("/subcollection");
});
Runtime output:
Uncaught (in promise) TypeError: model.collection is not a function
Instead I have to do:
fromFirestore: function (
snapshot: firebase.firestore.QueryDocumentSnapshot
): MyModel {
const model = snapshot.data();
// Some kind of validation, etc.
> model.ref = firebase.firestore().doc(snapshot.ref.path);
return model as MyModel;
},