Reputation: 15976
json_serializable supports nested classes:
https://docs.flutter.dev/development/data-and-backend/json#generating-code-for-nested-classes
My goal is to have a Parent class with a Child member, and I want the firestore to look like:
Collection(Parent) -> {parentId} -> Collection(Child) -> {childId}
What is not clear is how the firestore that backs this model is supposed to be structured and accessed.
Any ideas? Thank you
Upvotes: 0
Views: 345
Reputation: 1412
This could help https://firebase.flutter.dev/docs/firestore-odm/subcollections/ but it's not ready for production.
In the meantime, I'd create instances (with json_serializable) programmatically, like:
QuerySnapshot subCollQuerySnapshot = await FirebaseFirestore.instance
.collection("maincoll") //
.doc(mainDoc.id) //
.collection("subcoll") //
.get();
for (var subCollDoc in subCollQuerySnapshot.docs) {
MySubCollClass mySubCollInstance = MySubCollClass.fromJson(subCollDoc.data());
// ... add mySubCollInstance to your mainInstance's list
}
Upvotes: 1