title: How to correctly initiate n:m associations in Sequelize
body: <p>In my express app, I have two models which I want to associate with each other through an n:m-association: <code>User</code>, <code>Game</code>. This should pass via the joint model <code>GamePlayer</code>. I read in the <a href="https://sequelize.org/master/manual/assocs.html#many-to-many-relationships" rel="nofollow noreferrer">Sequelize Docs</a> that I have to call <code>.belongsToMany()</code> on both <code>User</code> and <code>Game</code>. However, as soon as I do this, my app crashes with the error <code>GameScore.belongsTo called with something that's not a subclass of Sequelize.Model</code>. As shown, there is also a <code>GameScore</code> model, which belongs to <code>Game</code> and <code>Game</code> always has one <code>GameScore</code>. I tried setting a <code>references</code> object in the <code>GameScore</code> model, I tried using <code>.hasMany()</code> in <code>GamePlayer</code> along with <code>.belongsTo(GamePlayer)</code> in both <code>User</code> and <code>Game</code>, all to no avail. As soon as I remove the association, the app doesn't crash anymore. I don't know, if I'm misunderstanding something here, or if I'm just being blind/missing the forest for the trees. Any help would me much appreciated!</p>
  <p>I'm using version <code>6.3.3</code> of Sequelize.</p>
  <p>Find below the relevant code of all the involved models (imports and interface declarations omitted):</p>
  <p><strong>User Model</strong></p>
  <pre><code>export default class User extends Model { /* ... just variable declarations */ }
  
  User.init({
      id: {
          type: DataTypes.UUID,
          defaultValue: DataTypes.UUIDV4,
          primaryKey: true,
      },
      username: {
          type: DataTypes.STRING(50),
          allowNull: false,
      },
      email: {
          type: DataTypes.STRING(255),
          allowNull: false,
      },
      password: {
          type: DataTypes.STRING(255),
          allowNull: false,
      },
      deleted: {
          type: DataTypes.BOOLEAN,
          allowNull: false,
          defaultValue: false,
      },
  }, {
      tableName: 'users',
      sequelize: db,
      underscored: true,
  });
  
  User.belongsToMany(Game, {
      through: GamePlayer,
  });
  </code></pre>
  <p><strong>Game Model</strong></p>
  <pre><code>export default class Game extends Model { /* ... just variable declarations */ }
  
  Game.init({
      id: {
          type: DataTypes.UUID,
          defaultValue: DataTypes.UUIDV4,
          primaryKey: true,
      },
      deleted: {
          type: DataTypes.BOOLEAN,
          allowNull: false,
          defaultValue: false,
      },
  }, {
      tableName: 'games',
      sequelize: db,
      underscored: true,
  });
  
  Game.hasOne(GameScore);
  
  Game.belongsToMany(User, {
      through: GamePlayer,
  });
  </code></pre>
  <p><strong>GamePlayer Model</strong></p>
  <pre><code>export default class GamePlayer extends Model { /* ... just variable declarations */ }
  
  GamePlayer.init({
      gameId: {
          type: DataTypes.UUID,
          references: {
              model: Game,
              key: 'id',
          }
      },
      userId: {
          type: DataTypes.UUID,
          references: {
              model: User,
              key: 'id',
          }
      },
      team: {
          type: DataTypes.TINYINT({ 
              length: 1, 
              unsigned: true,
          }),
          allowNull: false,
      },
      win: {
          type: DataTypes.BOOLEAN,
          allowNull: false,
      },
  }, {
      tableName: 'game_players',
      sequelize: db,
      underscored: true,
  });
  </code></pre>
  <p><strong>GameScore Model</strong></p>
  <pre><code>export default class GameScore extends Model { /* ... just variable declarations */ }
  
  GameScore.init({
      gameId: {
          type: DataTypes.UUID,
          allowNull: false,
      },
      scoreTeam1: {
          type: DataTypes.TINYINT({
              length: 1,
              unsigned: true,
          }),
          allowNull: false,
      },
      scoreTeam2: {
          type: DataTypes.TINYINT({
              length: 1,
              unsigned: true,
          }),
          allowNull: false,
      },
  }, {
      tableName: 'game_scores',
      sequelize: db,
      underscored: true,
  });
  
  GameScore.belongsTo(Game, {
      foreignKey: 'gameId',
  });
  </code></pre>