You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm sorry for the late response but sadly I there's no way to query subcollections directly before fetching the collection. That's because the path must be constructed before querying a subcollection and so far we have no way of doing this in userland.
A suggestion would be to set eager loading properties when querying the data:
(This is my first time seeing this repo, I haven't used it yet haha! So sorry if the following code makes no sense at all)
constband=awaitbandRepository.whereGreaterThan(band=>band.formationYear,1985).whereArrayCointain(band=>band.genres,'progressive-rock').eagerLoad(band=>band.albums)// <- when querying, state which properties are subcollections that should be eager loaded..find();console.log(band.albums.map(album=>album.name)// correctly prints the albums' names
// QueryBuilderfunctioneagerLoad(...props: IWherePropParam<T>[]){for(constpropofprops){if(isSubcollection){// check if the property has the subCollection decoratorthis.eagerLoadProps.push(prop)}}}
// BaseFirestoreRepositoryasyncexecute(queries: Array<IFireOrmQueryLine>,limitVal?: number,orderByObj?: IOrderByParams,single?: boolean,customQuery?: ICustomQuery<T>eagerLoadedProps?: IWherePropParam<T>[]): Promise<T[]>{letquery=queries.reduce<Query>((acc,cur)=>{constop=cur.operatorasWhereFilterOp;returnacc.where(cur.prop,op,cur.val);},this.firestoreColRef);
...
constexecutedQuery=query.get().then(this.extractTFromColSnap);// The following code definitely does not work, but I think it will explain the ideaif(executedQuery.eagerLoadedProps){returnawaitPromise.all(eagerLoadedProps.map((prop)=>executedQuery.propName=firestore.getAll(prop())))}returnexecutedQuery}
I know this is not the correct code, but I hope it could give some light on a solution for this :)
As the title said when I'm querying a document that contains a subcollection, can this subcollection be automatically queried?
In this example,
wishes
is a subcollection of the document wishlist, but since I receive wishes not queried, I need to query it manuallyI've recently started using this amazing orm, sorry if I'm doing something wrong
The text was updated successfully, but these errors were encountered: