I have the following Firebase structure with:
A list of bakeries:
firebaseio.com/bakery/:id/stuffAboutTheBakery
And a list of bakers:
firebaseio.com/baker/:id/bakery/bakeryId
Bakers can provide bread to several bakeries so in the baker details I have an object that lists all the bakeries they supply using the bakery ID as a key and a value of true.
In my app I have a $firebaseObject with a baker. I want to get an array with the details of the bakeries they service. I can obviously just go to each end point but surely there is a better way. So my questions are:
- Is this data structure what the documentation means by flat structure? Or is there a better way to structure this?
- How do I query several specific bakeries into an array?
This is my current code:
self.baker = $firebaseObject(firebase.baker.child($stateParams.id));
self.baker.$loaded()
.then(function() {
self.bakeries = [];
for (var bakery in self.baker.bakeries) {
self.bakeries.push($firebaseObject(firebase.bakery.child(bakery)));
}
})
.catch(function(err) {
console.error(err);
});