I'd like to join data from my trainings-table
into my users-table
.
The data structure it like this:
- users
- key1
- name
- trainingIds
- t_key1
- t_key3
- trainings
- t_key1
- name
- description
- t_key2
- name
- description
- t_key3
- name
- description
I've already searched Stackoverflow and found a nice solution. Unfortunately, I wasn't able to solve the problem mentioned by Romain Bruckert.
This is my code:
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 is 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" : "email@web.de",
"trainingIds" : {
"-KdGH3qNKCWGnW1kebMj" : false,
"-KdHSzTb63L9_6qw461X" : true
},
"username" : "didi"
},
"EWt2O16J9MasAwuoi92PQ3h66Bw2" : {
"email" : "email@yahoo.de",
"username" : "ChrisB"
}
}
}
As suggested by Clark, I already imported the rxjs map
operator, but this does not solve the problem. The problem seems to be the list of trainingIds. These aren't returned as an array as expected but rather as an object. This can be seen in the console log.
Consolelog:
Any Idea how to solve this problem?