json_serializable支持嵌套类:
https://docs.flutter.dev/development/data-and-backend/json generating-code-for-nested-classes
我的目标是有一个带有Child成员的Parent类,并且我希望firestore看起来像:
Collection(Parent) -> {parentId} -> Collection(Child) -> {childId}
目前尚不清楚的是,支持该模型的firestore应该如何结构化和访问。
任何想法?谢谢你
这可以帮助https://firebase.flutter.dev/docs/firestore-odm/subcollections/,但还没有准备好用于生产。
同时,我将以编程方式创建实例(使用json_serializable),如:
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
}