title: Sequelize Error: you must use the 'as' keyword to specify the alias of the association you want to include. - node.js
body: <p>I am making a web application which is similar to 'Twitter'.</p>
  <p>When I ran the server,</p>
  <p>'user is associated to user multiple times. To identify the correct association,
  You must use the 'as' keyword to specify the alias of the association you want to include.'
  &lt;- this message appeared.</p>
  <p>I applied 'as' keyword for the relationship  between 'followers' and 'followings'.
  but the error message kept on appearing.</p>
  <h2>I'm sure that I did something wrong in someway, but I can't figure out what exactly it is.
  can somebody help me?</h2>
  <ol>
  <li>models/index.js</li>
  </ol>
  <pre><code>
      'use strict';
  
  const fs = require('fs');
  const path = require('path');
  const Sequelize = require('sequelize');
  const basename = path.basename(__filename);
  const env = process.env.NODE_ENV || 'development';
  const config = require(__dirname + '/../config/config.json')[env];
  const db = {};
  
  let sequelize;
  if (config.use_env_variable) {
      sequelize = new Sequelize(process.env[config.use_env_variable], config);
    } else {
        sequelize = new Sequelize(config.database, config.username, config.password, config);
    }
  
  fs
    .readdirSync(__dirname)
    .filter(file =&gt; {
      return (file.indexOf('.') !== 0) &amp;&amp; (file !== basename) &amp;&amp; (file.slice(-3) === '.js');
    })
    .forEach(file =&gt; {
      const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
      db[model.name] = model;
    });
  
  Object.keys(db).forEach(modelName =&gt; {
    if (db[modelName].associate) {
      db[modelName].associate(db);
    }
  });
  
  db.sequelize = sequelize;
  db.Sequelize = Sequelize;
  db.User = require('./user')(sequelize, Sequelize);
  db.Post = require('./post')(sequelize, Sequelize);
  db.Hashtag = require('./hashtag')(sequelize, Sequelize);
  
  db.User.hasMany(db.Post); //1 : n
  db.Post.belongsTo(db.User); 
  // m: n
  db.Post.belongsToMany(db.Hashtag, { through: 'PostHashtag' });
  db.Hashtag.belongsToMany(db.Post, { through: 'PostHashtag' });
  
  // I use alias here *****
  db.User.belongsToMany(db.User, {
    foreignKey: 'followingId',
    as: 'Followers',
    through: 'Follow',
  });
  
  db.User.belongsToMany(db.User, {
    foreignKey: 'followerId',
    as: 'Followings',
    through: 'Follow',
  });
  
  module.exports = db; 
  
  </code></pre>
  <ol start="2">
  <li>models/user.js</li>
  </ol>
  <pre><code>    module.exports = (sequelize, DataTypes) =&gt; (
    sequelize.define('user', {
      email: {
        type: DataTypes.STRING(40),
        allowNull: true,
        unique: true,
      },
      nick: {
        type: DataTypes.STRING(15),
        allowNull: false,
      },
      password: {
        type: DataTypes.STRING(100),
        allowNull: true,
      },
      provider: {
        type: DataTypes.STRING(10),
        allowNull: false,
        defaultValue: 'local',
      },
      snsId: {
        type: DataTypes.STRING(30),
        allowNull: true,
      },
    }, {
      timestamps: true,
      paranoid: true,
    })
  );
  
  
  </code></pre>
  <ol start="3">
  <li>models/post.js</li>
  </ol>
  <pre><code>module.exports = (sequelize, DataTypes) =&gt; (
    sequelize.define('user', {
      email: {
        type: DataTypes.STRING(40),
        allowNull: true,
        unique: true,
      },
      nick: {
        type: DataTypes.STRING(15),
        allowNull: false,
      },
      password: {
        type: DataTypes.STRING(100),
        allowNull: true,
      },
      provider: {
        type: DataTypes.STRING(10),
        allowNull: false,
        defaultValue: 'local',
      },
      snsId: {
        type: DataTypes.STRING(30),
        allowNull: true,
      },
    }, {
      timestamps: true,
      paranoid: true,
    })
  );
  
  </code></pre>
  <ol start="4">
  <li>models/hashtag.js</li>
  </ol>
  <pre><code>
  module.exports = (sequelize, DataTypes) =&gt; (
      sequelize.define('hashtag', {
          title: {
              type: DataTypes.STRING(15),
              allowNull: false,
              unique: true,
          },
      }, {
          timestamps: true,
          paranoid: true,
      })
  ); 
  </code></pre>