Firestore, how to combine more than 2 references to the collection at the same time

☆樱花仙子☆ 提交于 2020-01-16 19:01:10

问题


I use the method described in

Firestore how to get the collection value from another collection document id is referenced

but i've to combinate two reference document in one time but in other collections like:

cash.models.ts:

import { DocumentReference } from "@angular/fire/firestore";

export class Cash {  // .collection('contactors')
  id: string;
  person: DocumentReference<Workers>;
  contactor: DocumentReference<Contactors>;
  nr_dokumentu: string;
  kwota: number;
  data: string;
}

export class Workers {
  id: string;
  imie: string;
  nazwisko: string;
}

export class Contactors {
  id: string;
  .
  .
  .
  kontakttelefon: string;
}

first i add combinated person references to Cash and it works fine

cash.service.ts:

...
getCash(){
  return this.cashCollection.snapshotChanges().pipe(map(changes => {
    return changes.map(a => {
      let data = a.payload.doc.data() as Cash;
      const workerId = data.osoba.path;

      const contactorId = data.contactor.path

      delete data.osoba
      return this.firestore.doc(workerId).valueChanges().pipe(map((collWorkerData: Workers) => {
        return Object.assign({
          person: {
            id: a.payload.doc.data().person.id,
            imie: collWorkerData.imie,
            nazwisko: collWorkerData.nazwisko
          },
           ...data });
      }))
    })
  })).pipe(mergeMap(cash => combineLatest(cash)))
}
...

but now, i've to get combinate with collection('contactor') into collection('cash'). I don't know where I need to implementate the code and how to return everything together, becouse i already used return statement.

This is my first app with firestore. Please help me. Thank you

来源:https://stackoverflow.com/questions/54141647/firestore-how-to-combine-more-than-2-references-to-the-collection-at-the-same-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!