title: how to link userId with post table
body: <p>I am trying to link userId in user table with each post in post table.</p>
  <p>Here is my <strong>Post model</strong>:-</p>
  <pre><code>const Post = db.define(
  &quot;Post&quot;,
  {
  id: {
    type: Sequelize.INTEGER,
    primaryKey: true,
    autoIncrement: true,
  },
  title: {
    type: Sequelize.STRING,
  },
  userId: {
    type: Sequelize.INTEGER,
  },
  },
  );
  </code></pre>
  <pre><code>User.hasMany(Post, { foreignKey: &quot;userId&quot; });
  
  Post.belongsTo(User, { foreignKey: &quot;userId&quot; });
  </code></pre>
  <p>Here is my <strong>User Model</strong>:-</p>
  <pre><code>    const User = db.define(
      &quot;User&quot;,
      {
      id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
      },
      name: {
        type: Sequelize.STRING,
      },
      email: {
        type: Sequelize.STRING,
      },
      password: {
        type: Sequelize.STRING,
      },
      },
      );
  </code></pre>
  <p>and here is my <strong>post request</strong>:-</p>
  <pre><code>     router.post(
        &quot;/&quot;,
      [
      upload.array(&quot;images&quot;, config.get(&quot;maxImageCount&quot;)),
      imageResize,
      ],
       async (req, res) =&gt; {
      const paths = await req.files.map((file) =&gt; ({ fileName: file.filename }));
      await Post.create(
        {
          title: req.body.title,
          userId: req.body.userId,
          Post_Images: paths.map((x) =&gt; ({ images: x.fileName })),
        },
        { include: [Post_Image] }
      ).then(
        res.status(201).send({
          msg: &quot;upload successful&quot;,
        }),
        (validation) =&gt; {
          res.status(422).json({
            errors: validation.errors.map((error) =&gt; {
              return {
                fieldName: error.path,
                message: error.message,
              };
            }),
          });
        }
      );
       }
       );
  </code></pre>
  <p>In my create call I tried using <code>userId: req.body.userId</code>, but it does not work it keeps returning userId null.</p>