title: rewrite left outer join for sub queries in bookshelf.js
body: <p>Note : I have not shared database schema as I am mainly looking for a help only w.r.t. last step which is 'left outer join' on 2 sub-queries. </p>
  
  <pre><code>select      *
  from
  
  (select     id
   from       Action
   where      id = 3) AS act1
  
  left Outer Join
  
  (select     Action.name, 
              completed_At as completedAt, 
              deadline, notes,
              ActionAssignedTo.action_Id as actionId, 
  from        Action 
  inner join  Employee 
  on          Action.created_By_Id = Employee.id 
  and         Employee.vendor_Id = 2
  inner join  ActionAssignedTo
  on          Action.id = ActionAssignedTo.action_Id 
  and         ActionAssignedTo.action_Id = 3  
  where       Action.created_By_Id = 7
  group by    Action.id 
  limit       2) AS act2
  
  on          act1.id = act2.actionId
  </code></pre>
  
  <p>I need to write this above query using Bookshelf</p>
  
  <pre><code>let options = {columns: [  'Action.name', 'completed_At as completedAt', 
                         'deadline', 'notes', 
                         'ActionAssignedTo.action_Id as actionId',
             ]};
  
    let action2 = new Action(); 
  
    action2.query().innerJoin('Employee',  function () {
                              this.on('Action.created_By_Id', 'Employee.id')
                             .andOn('Employee.vendor_Id', bookshelf.knex.raw(1));
    });
  
    action2.query().innerJoin('ActionAssignedTo',  function () {
                              this.on('Action.id',  'ActionAssignedTo.action_Id')                    
                             .andOn('ActionAssignedTo.action_Id', bookshelf.knex.raw(5));
    });
  
    action2.query().where(function() {
          this.where('Action.created_By_Id', empId)
    });
    action2.query().groupBy('Action.id'); 
    action2.query().limit(2);
    action2.query().columns(options.columns);
  
  
    let action1; 
  
    action1 =  Action.where('id', actionId);
    action1.query().columns('id');
  
    return bookshelf.knex.raw('select * from ' 
                      + '(' + action1.query().toString() + ') AS act1'
                      + ' left Outer Join '
                      + '(' + action2.query().toString() + ') AS act2'
                      + ' on act1.id = act2.actionId');
  </code></pre>
  
  <p>I am not keen on using bookshelf.knex.raw for using the left Outer Join as the output given by knex.raw and bookshelf differ. </p>
  
  <p>Is there a way I can do the 'left Outer Join' directly using bookshelf library.</p>
  
  <p>I looked into the code but it seems leftOuterJoin only takes table name as the first parameter and what I need is a query. </p>