title: Sequelize joining two tables which are not associated
body: <p>I am trying to retrieve data by joining two tables which are not "associated" using a relationship.  These two tables are as below:</p>
  
  <pre><code>mysql&gt; desc partner_txns;
  +------------+-------------+------+-----+---------+----------------+
  | Field      | Type        | Null | Key | Default | Extra          |
  +------------+-------------+------+-----+---------+----------------+
  | id         | int(11)     | NO   | PRI | NULL    | auto_increment |
  | txn_id     | int(11)     | NO   |     | NULL    |                |
  | user_id    | int(11)     | NO   | MUL | NULL    |                |
  | txn_type   | varchar(1)  | YES  |     | NULL    |                |
  | txn_amnt   | double      | YES  |     | NULL    |                |
  | desc       | varchar(64) | YES  |     | NULL    |                |
  | createdBy  | int(11)     | NO   | MUL | NULL    |                |
  | created_on | datetime    | NO   |     | NULL    |                |
  +------------+-------------+------+-----+---------+----------------+
  8 rows in set (0.00 sec)
  
  mysql&gt; desc accounts_master;
  +-------------+-------------+------+-----+---------+----------------+
  | Field       | Type        | Null | Key | Default | Extra          |
  +-------------+-------------+------+-----+---------+----------------+
  | id          | int(11)     | NO   | PRI | NULL    | auto_increment |
  | name        | varchar(64) | NO   |     | NULL    |                |
  | owner       | int(11)     | NO   | MUL | NULL    |                |
  | type        | int(11)     | YES  |     | 0       |                |
  | expires_on  | datetime    | NO   |     | NULL    |                |
  | max_lists   | int(11)     | YES  |     | 10      |                |
  | max_groups  | int(11)     | YES  |     | 10      |                |
  | createdBy   | int(11)     | NO   | MUL | NULL    |                |
  | modifiedBy  | int(11)     | NO   | MUL | NULL    |                |
  | created_on  | datetime    | NO   |     | NULL    |                |
  | modified_on | datetime    | NO   |     | NULL    |                |
  +-------------+-------------+------+-----+---------+----------------+
  11 rows in set (0.00 sec)
  </code></pre>
  
  <p>Without using sequelize, normally I would make an SQL query like this:</p>
  
  <pre><code>mysql&gt; select a.user_id, b.name from partner_txns a, accounts_master b where a.createdBy = 3 and a.user_id = b.owner;
  +---------+-------------+
  | user_id | name        |
  +---------+-------------+
  |       8 | New account |
  |       8 | Comviva     |
  |       8 | Infosys     |
  |       9 | HDFC        |
  |       9 | INTEGRA     |
  +---------+-------------+
  5 rows in set (0.00 sec)
  </code></pre>
  
  <p>What is the equivalent of doing this using Sequelize, assuming I have these two tables as two models as below:</p>
  
  <ul>
  <li>PartnerTxn</li>
  <li>Account</li>
  </ul>
  
  <p>I am tempted to use like:</p>
  
  <pre><code>var Model = require('ecp_model');
  
  Model.PartnerTxn.findAll({
    where: {createdBy:3 },
    include : [{model:Model.Account, attribute:['name']}]
  }).then(function(results) {
     console.log("results:", results);
  });
  [rv.nath@localhost authserver]$ 
  </code></pre>
  
  <p>But then this won't work because these two tables are not related.  So, I get an error as below:</p>
  
  <pre><code>Unhandled rejection Error: Account is not associated to PartnerTxn!
      at validateIncludedElement (/var/opt/ecp_db/node_modules/sequelize/lib/model.js:569:11)
      at /var/opt/ecp_db/node_modules/sequelize/lib/model.js:452:29
      at Array.map (native)
      at validateIncludedElements (/var/opt/ecp_db/node_modules/sequelize/lib/model.js:448:37)
      at null.&lt;anonymous&gt; (/var/opt/ecp_db/node_modules/sequelize/lib/model.js:1360:32)
      at tryCatcher (/var/opt/ecp_db/node_modules/bluebird/js/release/util.js:16:23)
      at Promise._settlePromiseFromHandler (/var/opt/ecp_db/node_modules/bluebird/js/release/promise.js:503:31)
      at Promise._settlePromise (/var/opt/ecp_db/node_modules/bluebird/js/release/promise.js:560:18)
      at Promise._settlePromise0 (/var/opt/ecp_db/node_modules/bluebird/js/release/promise.js:605:10)
      at Promise._settlePromises (/var/opt/ecp_db/node_modules/bluebird/js/release/promise.js:684:18)
      at Async._drainQueue (/var/opt/ecp_db/node_modules/bluebird/js/release/async.js:126:16)
      at Async._drainQueues (/var/opt/ecp_db/node_modules/bluebird/js/release/async.js:136:10)
      at Immediate.Async.drainQueues [as _onImmediate] (/var/opt/ecp_db/node_modules/bluebird/js/release/async.js:16:14)
      at processImmediate [as _immediateCallback] (timers.js:383:17)
  </code></pre>