0

I have a Firebase table named Orders:

{productID: xyz, 
 userID: abc, 
 quantity: 100}

There is another table Products containing product details. When showing a user's orders, I need to show some product details along with each order. How can I use $firebaseArray for this purpose?

$firebaseArray seems can only go with a table. Here, I'd need to query each ordered product's detail and add the detail to each order. Is the $extend the way to go? If so, any good example would be very appreciated.

Matthias A. Eckhart
  • 5,136
  • 4
  • 27
  • 34
webp
  • 1,311
  • 2
  • 13
  • 16
  • https://gist.github.com/katowulf/f78d4a224c06a643ddfa – Kato Aug 04 '15 at 20:05
  • http://jsfiddle.net/katowulf/uoe5yt8x/ – Kato Aug 04 '15 at 20:05
  • 1
    http://stackoverflow.com/questions/21721460/firebase-data-normalized-how-should-i-fetch-a-collection-based-on-this-structur/21733457#21733457 – Kato Aug 04 '15 at 20:11
  • possible duplicate of [Query for multiple records in firebase](http://stackoverflow.com/questions/29709227/query-for-multiple-records-in-firebase) – Kato Aug 04 '15 at 20:11
  • http://stackoverflow.com/questions/25512039/using-firebase-util-to-resolve-one-to-many-relationship – Kato Aug 04 '15 at 20:12
  • Hi @Kato, thanks for your comments. Following them, I've found the first example here https://github.com/firebase/firebase-util/blob/master/src/NormalizedCollection/README.md to be very similar to my problem and I am able to do what I need now. Firebase.util is very cool. – webp Aug 09 '15 at 03:37

1 Answers1

0

Just saw this one. What you want to use is the NormalizedCollection. This way you can write your statement something like this:

var fb = new Firebase('https://<instance>.firebaseio.com');
var norm = new Firebase.util.NormalizedCollection(
   fb.child('products'),
   fb.child('productDetails')
);
var productsRef = $firebaseArray(norm.ref());