title: Get data from multiple tables using Seqeulize
body: <p>I have two tables, Post and Comments, I am trying to get all posts by userId and also fetch the relevant comments for each post using the following code. I am getting all the posts but nodejs through an error <strong>&quot; comment is not associated to post&quot;</strong>.</p>
  <p><strong>Post Table</strong></p>
  <pre><code>const {Sequelize, DataTypes} = require('sequelize')
  const db = require('../config/db')
  
  const Post = db.define('post', {
      id:{
          type: DataTypes.INTEGER(255),
          autoIncrement: true,
          allowNull: false,
          primaryKey: true
      },
      postId:{
          type: DataTypes.UUID,
          defaultValue: Sequelize.UUIDV4
      },
      postText:{
          type: DataTypes.TEXT,
          allowNull: false
      },
      totalPostLikes: {
          type: DataTypes.INTEGER,
          allowNull: true,
          defaultValue: 0
      },
      totalPostStrikes: {
          type: DataTypes.INTEGER,
          allowNull: true,
          defaultValue: 0
      },
      totalPostQuotes: {
          type: DataTypes.INTEGER,
          allowNull: true,
          defaultValue: 0
      },
      totalPostShare: {
          type: DataTypes.INTEGER,
          allowNull: true,
          defaultValue: 0
      },
      userId:{
          type: DataTypes.INTEGER,
          allowNull: false,
          references: {
              model: 'users',
              key: 'id'
          } 
      }
  },{
      freezeTableName: true
    })
  
  module.exports = Post
  </code></pre>
  <p><strong>Comments Table</strong></p>
  <pre><code>const {Sequelize, DataTypes} = require('sequelize')
  const db = require('../config/db')
  
  const Comment = db.define('comment', {
      id:{
          type: DataTypes.INTEGER(255),
          autoIncrement: true,
          allowNull: false,
          primaryKey: true
      },
      commentUUID:{
          type: DataTypes.UUID,
          defaultValue: Sequelize.UUIDV4
      },
      commentText:{
          type: DataTypes.TEXT,
          allowNull: false
      },
      totalCommentLikes: {
          type: DataTypes.INTEGER,
          allowNull: true,
          defaultValue: 0
      },
      totalCommentStrikes: {
          type: DataTypes.INTEGER,
          allowNull: true,
          defaultValue: 0
      },
      totalCommentQuotes: {
          type: DataTypes.INTEGER,
          allowNull: true,
          defaultValue: 0
      },
      userId:{
          type: DataTypes.INTEGER,
          allowNull: false,
          references: {
              model: 'users',
              key: 'id'
          } 
      }, postId:{
          type: DataTypes.INTEGER,
          allowNull: false,
          references: {
              model: 'post',
              key: 'id'
          } 
      }
  },{
      freezeTableName: true
    })
  
    module.exports = Comment
  </code></pre>
  <p><strong>This is how I am creating tables and associations</strong></p>
  <pre><code>const db = require('../config/db')
  
  const User = require('./user')
  const Post = require('./posts')
  const Comments = require('./comments')
  
  
  User.hasMany(Post)
  Post.belongsTo(User)
  
  
  Post.hasMany(Comments)
  Comments.belongsTo(Post)
  User.hasMany(Comments)
  Comments.belongsTo(User)
  
  
  
  db.sync({force: true})
  .then((result) =&gt;{
      console.log(result)
  })
  .catch((error) =&gt; {
      console.log(error)
  })
  </code></pre>
  <p><strong>Code to fetch data</strong></p>
  <pre><code>router.get('/:id', authenticate, async (req,res) =&gt; {
  
      const { id } = req.params
  
  
      const data = await Post.findAll(
          {where: {userId: id},
          attributes: [
              'postText', 
              'totalPostLikes', 
              'totalPostStrikes',
              'totalPostQuotes',
              'totalPostShare'
          ],
           include:[{model: Comments, attributes:['commentText']}]   
      })
  
  
      try{
          res.send(data);
  
      } catch({errors}) {
          res.status(400).send(errors)
      }
  })
  </code></pre>