title: SQL query with one-to-many relationship with PostgreSQL
body: <p>I'm trying to aggregate a list of cart items with a query that relates through a line_items table. I've abstracted a simple example of my use case:</p>
  
  <p>my expected result would look like this:</p>
  
  <pre><code>cart_id  cart_total shopper_id items                                                        payment_id
        1         345         34 [{"name":"egg","price:"39"}]                                 AS34gsdVSWET4
        2          54         45 [{"name":"biscut","price:"5"},{"name":"apple","price:"15"}]  JFHERHJE$Y#$H
  </code></pre>
  
  <p>given a schema and data like:</p>
  
  <p>carts:</p>
  
  <pre><code>id  cart_total shopper_id
  1   39         34
  2   20         45
  </code></pre>
  
  <p>line_items:</p>
  
  <pre><code>id  cart_id    item_name item_price
  1   1          egg       39
  2   2          biscut     5
  3   2          apple     15
  </code></pre>
  
  <p>payment:</p>
  
  <pre><code>id  cart_id payment_id
  1   1       AS34gsdVSWET4
  2   2       JFHERHJE$Y#$H
  </code></pre>
  
  <p>How to get all cart list and get a list of carts for particular <code>shopperId</code>?</p>