title: Firebase: How to retrieve data from two tables using id
body: <p>I come from an SQL background and recently started using Firebase for building an ionic shopping cart. This is the database schema:</p>
  
  <p><a href="https://i.stack.imgur.com/gIjQF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gIjQF.png" alt="Shopping Cart Schema"></a></p>
  
  <p>To retrieve a <strong>user's</strong> cart, i used the following</p>
  
  <pre><code>    var user_id="user1"; // Temporary initialised
  
      var refCart = new Firebase("https://testing.firebaseio.com/cart");
      var cart=$firebase(fireBaseData.refCart().child(user_id)).$asArray();
  </code></pre>
  
  <p>This gives the result:</p>
  
  <pre><code>item1 1
  item2 2
  item3 5
  </code></pre>
  
  <p>So tried using <a href="https://www.firebase.com/docs/web/api/datasnapshot/foreach.html" rel="nofollow noreferrer">foreach()</a></p>
  
  <pre><code>var refMenu = new Firebase("https://testing.firebaseio.com/menu");
  refCart.child(user_id).on("value", function(snapshot) {
  
      snapshot.forEach(function(childSnapshot) {
  
        var item_id = childSnapshot.name();
        var qty = childSnapshot.val();
  
        //var data= refMenu.child(item_id).val();  
        // val is not a function
  
        //var data= refMenu.child(item_id).exportval(); 
        // exportval is not a function
  
        //var data = $firebase (refMenu.child(item_id)). $asArray(); 
        // Give me an array of objects , ie attributes - OK! But what to do next ?
  
        //console.log("DATA",data );
  
        console.log("Item",item_id+" "+qty);
  
     });
  
  });
  </code></pre>
  
  <p>How can i use <strong>item_id</strong> to retrieve <strong>item details</strong>.</p>
  
  <p>Is it the correct way of doing data retrieval from multiple tables?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Using <a href="https://www.firebase.com/docs/web/guide/retrieving-data.html" rel="nofollow noreferrer">on()</a> function , i managed to get the item attributes.</p>
  
  <pre><code>    refMenu.child(item_id).on("value", function(snapshot) {
        console.log("Price",snapshot.val().price);
      });
  </code></pre>
  
  <p>But is there any better implementation for the same.</p>
  
  <p>Is there any better ways to retrieve (from the server side) specific attributes for the item.
  Like in SQL</p>
  
  <pre><code>SELECT name,price, ... from menu;
  </code></pre>