lmcq / firebase-firestorm

Firebase Firestorm is an ORM for Firestore which can be used with Typescript.
MIT License
252 stars 19 forks source link

feat(query): add ability to pass property path array to where() and orderBy() methods #6

Open mkorenko opened 4 years ago

mkorenko commented 4 years ago

Currently it is not possible to make queries for nested object fields:

class Comment extends Entity {
  ...
  @field({ name: 'by' })
  by!: string;
}

@rootCollection({ name: 'posts' })
class Post extends Entity {
  ...
  @field({ name: 'pinnedComment' })
  pinnedComment!: Comment;
}
...
Collection(Post).query().where('pinnedComment.by', '==', 'userId').get();

Error: error TS2345: Argument of type '"pinnedComment.by"' is not assignable to parameter of type '... | "by" | "ref" | "toData"'. The proposal is to optionally pass an array of properties as a path:

Collection(Post).query().where(['pinnedComment', 'by'], '==', 'userId').get();