title: I have a problem with a one-to-many associated left outer join in sequelize.js
body: <p>The generated code ends up like LEFT OUTER JOIN ... ON tableA.id = tableB.headerId. Where it should be tableA.headerId = tableB.headerId.</p>
  <p>Here is the code I have at the moment:</p>
  <pre><code>        models.SalesOrdersLine.hasOne(models.SalesOrdersHeader, {
              foreignKey: 'salesOrderHeaderId',
              targetKey: 'salesOrderHeaderId'
          });
  
          let data = (await models.SalesOrdersLine.findAll({
              attributes:[
                  'branchName',
                  ['createdByName', 'salesPerson'],
                  [Sequelize.fn('count', 
                      Sequelize.fn('distinct',
                          Sequelize.col('SalesOrdersLine.salesOrderHeaderId')
                      )
                  ), 'uniqueTransactions'],
                  [Sequelize.fn('count', Sequelize.col('*')), 'uniqueProducts'],
                  [Sequelize.fn('sum', Sequelize.col('SalesOrdersLine.newSales')), 'sales'],
                  [Sequelize.literal('sum(SalesOrdersLine.newSales) / 1.1'), 'salesExclGst'],
                  [Sequelize.fn('sum', Sequelize.col('SalesOrdersLine.qty')), 'quantity'],
                  [Sequelize.fn('sum', Sequelize.col('SalesOrdersLine.qtyShipped')), 'quantityShipped'],
                  [Sequelize.literal('CASE WHEN COUNT(DISTINCT(SalesOrdersLine.salesOrderHeaderId)) = 0 THEN 0 ELSE COUNT(*)/COUNT(DISTINCT(SalesOrdersLine.salesOrderHeaderId)) END'), 'unitsPerTransaction'],
                  [Sequelize.literal('CASE WHEN COUNT(DISTINCT(SalesOrdersLine.salesOrderHeaderId)) = 0 THEN 0 ELSE SUM(SalesOrdersLine.newSales)/COUNT(DISTINCT(SalesOrdersLine.salesOrderHeaderId)) END'), 'aveTransactionValue'],
              ],
              include: [{
                  attributes: [['paymentAmount', 'paymentAmount']],
                  model: models.SalesOrdersHeader,
              }],
              group : ['salesPerson'],
              order: Sequelize.literal('sales DESC'),
              where: whereObj,
  
              logging: console.log,
              raw: true,
          }));
  </code></pre>