title: What is the references field for in sequelize?
body: <p>I have a user table that has a foreign key column to a roles table. </p>
  
  <p>I defined all relationships in mysql and using <code>sequelize-auto</code> I generated my models. </p>
  
  <p>The generated model for user was this: </p>
  
  <pre><code>  const user = sequelize.define('user', {
      Id: {
        type: DataTypes.INTEGER(11),
        allowNull: false,
        primaryKey: true,
        autoIncrement: true,
      },
      Email: {
        type: DataTypes.STRING(45),
        allowNull: false,
        unique: true,
      },
      RoleId: {
        type: DataTypes.INTEGER(11),
        allowNull: false,
        references: {
          model: 'roles',
          key: 'Id',
        },
      },
    });
  </code></pre>
  
  <p>I thought that my reference was set so that when I did the following in my resolver: </p>
  
  <pre><code>users: async () =&gt; {
    const users = await db.user.findAll({
      include: [
        {
          model: db.roles,
        },
      ],
    });
  
  return users
  </code></pre>
  
  <p>I should have gotten back a list of user roles with the following query in the playground: </p>
  
  <pre><code>{users
    {roles
     {Name, Id}
    }
  }
  </code></pre>
  
  <p>instead I got </p>
  
  <blockquote>
    <p>roles is not associated to user!</p>
  </blockquote>
  
  <p>What I later figured out is that I needed to make an association: </p>
  
  <pre><code>  user.associate = models =&gt; {
      user.hasMany(models.roles, {
        foreignKey: 'Id',
        sourceKey: 'RoleId',
        onDelete: 'cascade',
      });
    };
  </code></pre>
  
  <p>Then it worked. </p>
  
  <p>What I still dont understand is what is this for in the user-model?: </p>
  
  <pre><code> references: {
      model: 'roles',
      key: 'Id',
    },
  </code></pre>
  
  <p>I thought that it was my "association" with the roles table but without me explicitly adding an association this simply did nothing. Can someone please explain the meaning of <code>references</code> field?</p>