title: How to add an array of a model to another model in node js using sequelize while using a JOIN query
body: <p>So I am moving an application from JAVA to Nodejs. One of the DB schema is divided into Source and Facts. Each source can have multiple facts, and each fact is assigned to a single source. Now in JAVA when I run the following query:</p>
  
  <pre><code>SELECT SRC.SRC_ID, SRC.SRC_NM, FACTS.FACT_ID, FACT_NM, FACT_VAL 
  FROM TDAV_ALM_SRC_REG_M SRC 
  LEFT OUTER JOIN TDAV_SRC_FACTS_M FACTS ON SRC.SRC_ID = FACTS.SRC_ID 
  WHERE SRC.SRC_ID = ?
  </code></pre>
  
  <p>I use the following Mapping rule, defined in an xml:</p>
  
  <pre><code>&lt;resultMap id="sourceResult" type="com.sec.davs.olap.dto.OLAPSourceConfigDto"&gt;  
    &lt;result property="src_id" column="src_id"/&gt;
     &lt;result property="src_nm" column="src_nm"/&gt;
      &lt;collection property="factsList" ofType="com.sec.davs.olap.dto.OLAPFactsDto"&gt;     
          &lt;result property="fact_id" column="fact_id"/&gt; 
          &lt;result property="fact_nm" column="fact_nm"/&gt; 
          &lt;result property="fact_val" column="fact_val"/&gt; 
    &lt;/collection&gt;
  &lt;/resultMap&gt;
  </code></pre>
  
  <p>Here OLAPSourceConfigDto and OLAPFactsDto are POJOs and OLAPSourceConfigDto has an array of OLAPFactsDto defined inside it. Now the result that I get it is as follows:</p>
  
  <pre><code>{
      "result": {
          "respStat": "OK",
          "resp": {
              "src_id": 56,
              "src_nm": "ALM_SRC2",
              "factsList": [{
                  "fact_id": 38,
                  "fact_nm": "DTIME",
                  "fact_val": "dtime",
                  "src_id": 0
              }, {
                  "fact_id": 39,
                  "fact_nm": "DUID",
                  "fact_val": "duid",
                  "src_id": 0
              }]
          }
      }
  }
  </code></pre>
  
  <p>The ORM uses the JOIN query and maps all the rows from the FACTS that match into the array inside the source. MY UI is designed to handle the above response as well.</p>
  
  <p>NOW IN NODE JS, I am using sequelize. I have created a model for Source, a model for Facts, created an association between the two with Source.hasMany(facts), and ran the exact same query.</p>
  
  <p>Here are the models and the query:</p>
  
  <pre><code>const facts=sequelize.define('fact', {
      FACT_ID: {
          type: Sequelize.INTEGER,
          primaryKey: true
        },
        FACT_NM: {
          type: Sequelize.STRING
        },
        FACT_VAL: {
          type: Sequelize.STRING
        },
        SRC_ID: {
          type: Sequelize.INTEGER
        }
    },{
      tableName: 'Facts_Master',
      freezeTableName: true,
      timestamps: false
    });
  
    const sources=sequelize.define('source', {
      SRC_ID: {
          type: Sequelize.INTEGER,
          primaryKey: true
        },
        SRC_NM: {
          type: Sequelize.STRING
        }
    },{
      tableName: 'Source_Master',
      freezeTableName: true,
      timestamps: false
    });
  
  sources.hasMany(facts,{
      foreignKey: 'SRC_ID'
  })
  
  sources.findAll({
          raw: true,
          include: [{model: facts}],
          where:{
              SRC_ID : 56
          }
      }).then(data =&gt; {
          var json=JSON.stringify({
              result:data
          });
  console.log("New Data:"+json)
  })
  </code></pre>
  
  <p>This produces the result like so:</p>
  
  <pre><code>{
      "result": [{
          "SRC_ID": 56,
          "SRC_NM": "ALM_SRC2",
          "facts.FACT_ID": 38,
          "facts.FACT_NM": "DTIME",
          "facts.FACT_VAL": "dtime",
          "facts.SRC_ID": 56
      }, {
          "SRC_ID": 56,
          "SRC_NM": "ALM_SRC2",
          "facts.FACT_ID": 39,
          "facts.FACT_NM": "DUID",
          "facts.FACT_VAL": "duid",
          "facts.SRC_ID": 56
      }]
  }
  </code></pre>
  
  <p>Is there anyway to use sequelize and create the same kind of mapping I was able to get in JAVA, without having to change the query or apply some post query formatting.</p>
  
  <p>Thanks in advance.</p>