I've got a MeetingService that fetches data from my RethinkDB through HorizonIO. When trying to fetch a meeting through its ID, I'll always get a null value as response. Other methods in this service work without issue.
meeting.service.ts:
getMeetingById(passedId: string): Observable<Meeting[]> {
return this.table.find({meetingId: passedId}).fetch();
}
meeting-detail.component.ts:
currentMeeting: Meeting;
getCurrentMeeting(): void {
this._meetingsService.getMeetingById(this.passedId).subscribe(
(returnMeetings: Meeting[]) => {
this.currentMeeting = returnMeetings[0];
}
);
}
Even when I change the passedId to an ID I got directly from my db (through the admin panel), the method still returns null.
If I change the code to return the first value in the table everything will simply work.
getMeetingById(passedId: string): Observable<Meeting[]> {
return this.table.order("meetingId", "descending").limit(1).fetch();
}
The end result is error undefined on the currentMeeting var in my view:
EXCEPTION: Error in ./MeetingDetailComponent class MeetingDetailComponent - inline template:1:4 caused by:
Cannot read property 'meetingId' of undefined
Edit: Additional code showing the different implementatations:
load() {
if(this.passedId != null) {
this._feedService.GetFeedById(this.passedId).subscribe(
(returnFeed: Feed[]) => {
this.currentFeed = returnFeed[0];
}
);
} else {
this._feedService.GetFirstFeed().subscribe(
(returnFeed: Feed[]) => {
this.currentFeed = returnFeed[0];
}
);
}
}
Second one works, first one doesn't. The passed id is correct and and is also available in the database so this is quite confusing.
Thanks in advance.
Although no one seems to care for the question, I've found an answer that works relatively well. My temporary fix involved fetching the entire table and manually finding the right id through a for each but it's also possible like this:
Use find() and a lambda to call the right id.
getMeetingById(passedId: string): Observable<IMeeting> {
var allMeetings: Observable<Meeting[]>;
allMeetings = this.table.watch();
return allMeetings.flatMap((meetings: IMeeting[]) => Observable.from(meetings))
.find((meeting: IMeeting) => (meeting.id == passedId));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With