1

I have tried to understand how to structure data in Firebase, but I'm struggling to apply the examples to what I have, some advice would be great. Image of Database Structure

I have a list of portfolios. Each portfolio has a name and its own key (probably bad practice, but I couldn't work out how to get the key easily in my JS).

I have a list of orders. Each order has a name and portfolio attribute set to the key of the portfolio it belongs to.

  1. Do I have to store order ID's in my portfolio?
  2. How do I get a list of orders where order.portfolio equals portfolio.key?

I've tried to use equalTo, however I don't think I'm using it correctly.

    firebase.database().ref("orders").orderByChild("portfolio").equalTo(thisref.portfolio.key).on('value',  function(snapshot) {
      var orders = snapshot.val();
    });
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

1 Answers1

0

See answer to related question here: What's the best way of structuring data on firebase?

I'm practical terms personally I download all the data into a local "store" and then "join" the data as I need it based on the I'd On the record. So

  1. Yes
  2. Download both sets on app initiation and then use a for loop or a lodash filter to get all orders for given portfolio
BrightEyed
  • 366
  • 2
  • 10