This is the model class to store in firestore.
import { AngularFirestore, DocumentReference } from '@angular/fire/firestore';
export class FlightLeg {
date: string;
type: string;
fromRef: DocumentReference; // AYT Airport object's KEY in Firestore
toRef: DocumentReference; // IST {key:"IST", name:"Istanbul Ataturk Airport" }
}
I need to store FlightLeg object with reference value. In order to do this:
export class FlightRequestComponent {
constructor(private srvc:FlightReqService, private db: AngularFirestore) { }
addFlightLeg() {
const flightLeg = {
date: this.flightDate.toLocaleString(),
type: this.flightRevenue,
fromRef: this.db.doc('/IATACodeList/' + this.flightFrom).ref,
toRef: this.db.doc('/IATACodeList/' + this.flightTo).ref,
} as FlightLeg
.
..
this.srvc.saveRequest(flightLeg);
}
The service which can save the object with referenced to another object into firestore:
export class FlightReqService {
.
..
...
saveRequest(request: FlightRequest) {
this.db.collection(this.collRequest)
.add(req).then(ref => {
console.log("Saved object: ", ref)
})
.
..
...
}
}