Firestore, how to combine more than 2 references t

2019-08-17 15:18发布

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

0条回答
登录 后发表回答