title: How to relate in sequelize
body: <p>I am trying to relate my Users model with the Posts model, what I want to do is that the user when creating a post saves the post id in the 'posteds' field of the user model, but I can't do it</p>
  <p>Post Table:</p>
  <p><a href="https://i.stack.imgur.com/jiJOu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jiJOu.png" alt="enter image description here" /></a></p>
  <p>'posteds' shouldn't be there, it should be in the users table</p>
  <p>My relationships:</p>
  <pre><code>Users.hasMany(Posts, {foreignKey: 'posteds'})
  Posts.belongsTo(Users, {foreignKey : 'userId'})
  </code></pre>
  <p>Model User:</p>
  <pre><code>import { DataTypes, UUIDV4, Optional, Model} from &quot;sequelize&quot;
  import { connection } from &quot;../database&quot;
  import { hash, genSalt, compare } from &quot;bcryptjs&quot;;
  import Posts from &quot;./posts.model&quot;;
  
  export const rolesEnum: string[] = ['ADMIN_ROLE', 'MODERATOR_ROLE','USER_ROLE']
  
  interface UserAttributes{
      id: number,
      email: string,
      password: string,
      img_url: string,
      role: 'ADMIN_ROLE' | 'MODERATOR_ROLE' | 'USER_ROLE',
      created_at: Date,
      updated_at?: Date
  }
  
  
  interface UserCreationAttributes extends Optional&lt;UserAttributes, &quot;id&quot; | &quot;created_at&quot; | 'img_url'&gt; {}
  // We need to declare an interface for our model that is basically what our class would be
  interface UserInstance
    extends Model&lt;UserAttributes, UserCreationAttributes&gt;,
      UserAttributes {}
  
  
  
      
  const Users = connection.define&lt;UserInstance&gt;('users', {
      id: {
          type: DataTypes.UUID,
          primaryKey: true,
          defaultValue: UUIDV4,
          unique: true,
          allowNull: false
      },
      email: {
          type: DataTypes.STRING,
          unique: true,
          allowNull: false
      },
      password: {
          type: DataTypes.STRING,
          allowNull: false
      },
      img_url: {
          type: DataTypes.STRING,
          defaultValue: process.env.DEFAULT_IMAGE || 'default.svg',
          allowNull: false
      },
      role: {
          type: DataTypes.STRING,
          values: rolesEnum,
          defaultValue: 'USER_ROLE',
          allowNull: false
      },
      created_at: {
          type: DataTypes.DATE,
          defaultValue: DataTypes.NOW,
          allowNull: false
      },
      updated_at: {
          type: DataTypes.DATE,
          defaultValue: DataTypes.NOW,
  
      }
  },{
      timestamps: false
  })
  export default Users
  </code></pre>
  <p>Model Posts:</p>
  <pre><code>import { DataTypes, Optional, Model,  UUIDV4} from &quot;sequelize&quot;;
  import {connection} from &quot;../database&quot;;
  
  interface PostAttributes {
      id: number,
      title: string,
      description: string,
      categorys?: Array&lt;string&gt;,
      img_url: string,
      created_at: Date,
      updated_at?: Date,
      userId?: string;
  }
  
  interface PostCreationAttributes extends Optional&lt;PostAttributes, &quot;id&quot; | &quot;created_at&quot; |&quot;img_url&quot; | &quot;categorys&quot;&gt; {}
  // We need to declare an interface for our model that is basically what our class would be
  interface PostInstance
    extends Model&lt;PostAttributes, PostCreationAttributes&gt;,
      PostAttributes {}
  
  
  const Posts = connection.define&lt;PostInstance&gt;('posts', {
      id: {
          type: DataTypes.UUID,
          primaryKey: true,
          defaultValue: UUIDV4,
          unique: true
      },
      title: {
          type: DataTypes.STRING,
          allowNull: false
      },
      description: {
          type: DataTypes.STRING,
          allowNull: false
      },
      categorys: {
          type: DataTypes.ARRAY(DataTypes.ENUM('web-devlopment', 'recent', 'featured')),
          values: ['web-devlopment', 'recent', 'featured'] //HELP TO SEND MESSAGES OF ERROR
      },
      img_url: {
          type: DataTypes.STRING,
          allowNull: false,
          defaultValue: process.env.DEFAULT_IMAGE || 'default.svg'
      },
      created_at: {
          type: DataTypes.DATE,
          defaultValue: DataTypes.NOW,
          allowNull: false
      },
      updated_at: {
          type: DataTypes.DATE,
          defaultValue: DataTypes.NOW
      }
  },{
      timestamps: false
  })
  
  
  export default Posts
  </code></pre>