title: KnexJS loop of queries
body: <p>I'm very new with Node, KnexJS and promises and I'm trying to build a simple loop that queries items and then adds the pictures associated with them.</p>
  
  <p>I looked at this answer and while it teaches a few things I don't think it works for my case: <a href="https://stackoverflow.com/questions/22957032/knex-transaction-with-promises#">Knex Transaction with Promises</a></p>
  
  <p>So far I have this:</p>
  
  <pre class="lang-html prettyprint-override"><code>router.get('/', function(req, res, next) {
    knex('parts').where(req.query)
      .orderBy('date_updated', 'DESC')
      .then(function(data){
  
        for (var k in data) {
          knex('photos')
            .select()
            .where('part_id', data[k].id)
            .then(function(photos){
              data[k].photos = photos;
            });
        }
        return data;
  
      })
      .then(function(data){
        res.render('parts/index', { title: 'Express', data: data, query: req.query });
      });
  });
  </code></pre>
  
  
  
  <p>Which is obviously wrong, but I just don't know the approach in these cases.</p>