[cloud_firestore] A way to nest collections in type safe way #6014
Unanswered
stargazing-dino
asked this question in
Feature request
Replies: 1 comment 1 reply
-
That's something I've been thinking about too. What I had in mind is: final movies = firestore.collection('movies').withConverter<Movie>(...);
final movieReviews = movies.subCollection('review').withConverter<Review>(...);
final reviewComments = movieReviews.subCollection('comments').withConverter<Comment>(...);
void main() async {
List<DocumentSnapshot<Review>> starWarsReviews = await movieReview(movies.doc('star-wars'))
.get().then((s) => s.docs);
List<DocumentSnapshot<Review>> metacriticStarWarsComments = await reviewComments(movieReview(movies.doc('star-wars')))
.get().then((s) => s.docs);
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello ! The new WithConverter is great. However I'm currently trying to find a good way to nest a
WithConverterCollectionReference<T>
on an instance ofWithConverterQueryDocumentSnapshot<T>
without the use of extensions.For example, say I have a profile collection reference:
Profiles can have the sub collection
badges
of type<UserBadge>
. I can make an extension for the typeWithConverterQueryDocumentSnapshot<Profile>
so that I can get the specific collection like this:That's great but I don't really think extensions methods are all that useful. Also, with further nested sub collections, the above only gets crazier. Here is an example of collection several layers nested.
It doesn't look very good and it relies on a lot of iffy string concatenation.
It'd be great if we were given a way to add
CollectionRefs
to aDocumentRef
so that we could index into a subcollection via a document. Soomething like this (off the top of my head) where the sub collection _usersBadgesRef'scollection
would start from the location of a child documentcc @rrousselGit
Beta Was this translation helpful? Give feedback.
All reactions