I need to merge data from my trainings-table
with my users-table
.
The structure of the data is as follows:
- users
- key1
- name
- trainingIds
- t_key1
- t_key3
- trainings
- t_key1
- name
- description
- t_key2
- name
- description
- t_key3
- name
- description
After researching on Stackoverflow, I came across a helpful solution. However, I encountered an issue mentioned by Romain Bruckert that I was unable to resolve.
This is the code I have so far:
this.visibleUser$ = af.database.list(`${this.path}`)
.map( users => {
console.log( users );
return users.map( user => {
console.log( user );
console.log( user.trainingIds );
user.trainingIds.map( trainingIdsMap => {
af.database.list(`dev/trainings/${trainingIdsMap.$key}`)
.map( tr => {
trainingIdsMap = tr;
});
});
return user
});
}) as FirebaseListObservable<any>;
This represents the Firebase data structure:
{
"trainings" : {
"-KdGENe4XiCyEowgYGbu" : {
"description" : "lala beschreibung",
"name" : "Bring Sally Up Challenge"
},
"-KdGGjQtvdLPWZOSHjKP" : {
"description" : "Beschreibung für liegestütz",
"name" : "Ligestütze"
},
"-KdGH3qNKCWGnW1kebMj" : {
"active" : false,
"description" : "Des funktioniert ja wirklich",
"name" : "Wahnsinn"
},
"-KdHSzTb63L9_6qw461X" : {
"description" : "klettern klettern klettern",
"name" : "8a Training"
},
"-KdI2OXgEO0GnIqDXaDT" : {
"description" : "Bes",
"name" : "Test"
}
},
"users" : {
"8faYwT4xp4SoXzU3HPnc2rIsqyp1" : {
"email" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2b4e464a42476b5c4e49054f4e">[email protected]</a>",
"trainingIds" : {
"-KdGH3qNKCWGnW1kebMj" : false,
"-KdHSzTb63L9_6qw461X" : true
},
"username" : "didi"
},
"EWt2O16J9MasAwuoi92PQ3h66Bw2" : {
"email" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c1a4aca0a8ad81b8a0a9aeaeefa5a4">[email protected]</a>",
"username" : "ChrisB"
}
}
}
I have followed Clark's suggestion and imported the rxjs map
operator, but it did not resolve the issue. The problem appears to be with the list of trainingIds, which are returning as an object instead of an array as expected, as shown in the console logs.
Console log: Stack Overflow Discussion
Any suggestions on how to overcome this challenge?