I am working on a flutter app that allows a user to select and book a trip. The data source is Firestore and is configured as follows:
Firestore -- Root
|
trips -- collection
|
Auto-ID -- Document
|
bookings -- collection
|
Auto-ID -- Document
There are a list of trip documents that are created with an Auto-ID and placed in the trips collection.
A user can select a trip and make a booking and this creates a document in the bookings collection. (subCollection of trips)
I can get a list of all the bookings for one trip using the following query:
Stream<QuerySnapshot> getAllBookings(document) {
return db
.collection('trips')
.document(document)
.collection('bookings')
.snapshots();
}
I can get a booking by one user using the following query:
Stream<QuerySnapshot> getUserBookings(document, user) {
return db
.collection('trips')
.document(document)
.collection('bookings')
.where('user', isEqualTo: user)
.snapshots();
}
But I cannot fathom out how to combine the two to loop over all the trips to find all the trips booked by one user and return this as a stream.
Any help would be much apprciated.