AngularFire query denormalised data


#1

Hey guys, i’m having some problem querying my data with firebase.

I have the below structure

The user has some pets and i want to get a list of all pets the user has in the pets node.
I did the following approach:

for (let petUID in this.user.pets) {
   this.af.database.object("/pets/" + petUID ).subscribe(data => {
      this.ownPets.push(data);
   });
}

At the end i get all the pets in my ownPets variable.
But it just like awkward to me this approach.

If any data is updated in the pets node from a pet that is inside the ownPets array, this pet is pushed again and i get the outdated and the new pet inside the ownPets.

I tried another approach: use the query method and send an array of objects in the equalTo but i get an error saying i can’t send an array of objects.

this.af.database.list('/pets', {
    query: {
      orderByChild: "name",
      equalTo: ["pet1", "pet2"]
    }
  }).subscribe (data => {
    console.log(data);
});

Anyone have a better approach i can use?
Thanks


#2

sounds like this is a firebase specific issue, maybe you should bring it up to them?


#3

@mhartington i know that it is not a ionic problem.
But lot of ppl here use firebase, so i was hoping someone had some similar problem using denormalised data.