title: Best Practice Data Relationships and Selecting with Firebase
body: <p>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.
  <a href="https://i.stack.imgur.com/C5ekv.jpg" rel="nofollow noreferrer">Image of Database Structure</a></p>
  
  <p>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).</p>
  
  <p>I have a list of orders. Each order has a name and portfolio attribute set to the key of the portfolio it belongs to.</p>
  
  <ol>
  <li>Do I have to store order ID's in my portfolio?</li>
  <li>How do I get a list of orders where order.portfolio equals portfolio.key?</li>
  </ol>
  
  <p>I've tried to use equalTo, however I don't think I'm using it correctly.</p>
  
  <pre><code>    firebase.database().ref("orders").orderByChild("portfolio").equalTo(thisref.portfolio.key).on('value',  function(snapshot) {
        var orders = snapshot.val();
      });
  </code></pre>