Comments (2)
Hi!
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.
I'm open to suggestions though
from fireorm.
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)
// Entity
import { Collection, SubCollection, ISubCollection } from 'fireorm';
class Album {
id: string;
name: string;
year: number;
}
@Collection()
export class Band {
id: string;
name: string;
formationYear: number;
genres: Array<string>;
@SubCollection(Album)
albums?: ISubCollection<Album>;
}
const band = await bandRepository
.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
// QueryBuilder
function eagerLoad(...props: IWherePropParam<T>[]) {
for (const prop of props) {
if (isSubcollection) { // check if the property has the subCollection decorator
this.eagerLoadProps.push(prop)
}
}
}
// BaseFirestoreRepository
async execute(
queries: Array<IFireOrmQueryLine>,
limitVal?: number,
orderByObj?: IOrderByParams,
single?: boolean,
customQuery?: ICustomQuery<T>
eagerLoadedProps?: IWherePropParam<T>[]
): Promise<T[]> {
let query = queries.reduce<Query>((acc, cur) => {
const op = cur.operator as WhereFilterOp;
return acc.where(cur.prop, op, cur.val);
}, this.firestoreColRef);
...
const executedQuery = query.get().then(this.extractTFromColSnap);
// The following code definitely does not work, but I think it will explain the idea
if (executedQuery.eagerLoadedProps) {
return await Promise.all(eagerLoadedProps.map((prop) => executedQuery.propName = firestore.getAll(prop())))
}
return executedQuery
}
I know this is not the correct code, but I hope it could give some light on a solution for this :)
from fireorm.
Related Issues (20)
- Can't resolve 'class-validator' typescript HOT 1
- Support for BulkWriter HOT 2
- Getter methods decorated with @Ignore() are still saved HOT 2
- plainToClass is undefined HOT 2
- TypeError: classTransformer.plainToClass error when trying to find document from DB HOT 2
- Rename id in collection to _id HOT 2
- Feature Request: Support generic validation HOT 3
- The result of build has some nulls removed
- Error: Collection with name ClubPlayers has already been registered HOT 1
- how to parameterize the complex query options? HOT 1
- If we are inside a transaction, our subcollections should also be TransactionRepositories HOT 1
- Querying subcollection of subcollection seems to inject random doc number on its path HOT 1
- SubCollection does not create HOT 2
- Project Status HOT 2
- Querying missing fields HOT 3
- Add firestore timestamps to entities HOT 1
- Error: Firestore must be initialized first - on using customRepository HOT 2
- firebase-admin SDK Timestamps no longer compatible with fireorm collection-update method HOT 1
- Feature Request: Graceful Handling of Duplicate Collections/Subcollections for Fireorm v >=0.18.0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fireorm.