title: Sequelize many-to-many relationship table gets unneeded extra column
body: <p>I'm trying to define a M:N relationship between models <code>Survey</code> and <code>Question</code>. The name of the relationship is <code>SurveyHasQuestions</code> which also has a definition (see further down how it's used in the associations definitions):</p>
  
  <pre><code>var SurveyHasQuestions = sequelize.define('survey_has_questions', {
      shq_id: {
          type: Sequelize.INTEGER,
          primaryKey: true,
          autoIncrement: true
      }
  }, {
      tableName: 'survey_has_questions'
  });
  </code></pre>
  
  <p>Tables for <code>Survey</code> and <code>Question</code> are generated correctly in the DB (which btw is Postgres):</p>
  
  <pre><code>survey_id: integer (pkey)
  survey_url: string
  date: timestamp
  </code></pre>
  
  <p>and</p>
  
  <pre><code>question_id: integer (pkey)
  question_text: string
  </code></pre>
  
  <p>Now, the following associations:</p>
  
  <pre><code>Survey.hasMany(SurveyQuestion, {through: SurveyHasQuestions, foreignKey: 'survey_id'});
  SurveyQuestion.hasMany(Survey, {through: SurveyHasQuestions, foreignKey: 'question_id'});
  SurveyHasQuestions.belongsTo(Survey, {foreignKey: 'survey_id'});
  SurveyHasQuestions.belongsTo(SurveyQuestion, {foreignKey: 'question_id'});
  </code></pre>
  
  <p>work correctly i.e. they generate a <code>survey_has_questions</code> table for the M:N relationship with the desired structure:</p>
  
  <pre><code>shq_id: integer (pkey)
  question_id: integer (fkey references survey_question.question_id)
  survey_id: integer (fkey references survey.survey_id)
  </code></pre>
  
  <p>but sequelize complains with the warning: <code>Using 2 x hasMany to represent N:M relations has been deprecated. Please use belongsToMany instead</code></p>
  
  <p>So in an effort to do things correctly, I've tried using only <code>belongsToMany()</code>. But these associations:</p>
  
  <pre><code>SurveyQuestion.belongsToMany(Survey, {
      through: SurveyHasQuestions,
      foreignKey: 'question_id'
  });
  Survey.belongsToMany(SurveyQuestion, {
      through: SurveyHasQuestions,
      foreignKey: 'survey_id'
  });
  </code></pre>
  
  <p>generate for <code>survey_has_questions</code> the incorrect table:</p>
  
  <pre><code>shq_id: integer (pkey)
  question_id: integer (fkey references survey_question.question_id)
  survey_survey_id: integer (fkey references survey.survey_id) &lt;---??? UNWANTED
  survey_id: integer (fkey references survey.survey_id)
  </code></pre>
  
  <p>The problem is the extra column <code>survey_survey_id</code> which serves absolutely nothing as it's a duplicate of the other column <code>survey_id</code>.</p>
  
  <p>The interesting part is that if I reverse the order of the <code>.belongsToMany()</code> statements, I get an extra field <code>survey_question_question_id</code> in place of the <code>survey_survey_id</code>.</p>
  
  <p>Now I know that I can <code>fix</code> this situation if in the definition of <code>SurveyHasQuestions</code> I remove my own primary key <code>shq_id</code> and let the combination of the fkeys serve as the pkey. But even though technically the serial pkey may not offer anything in the relationship (it might even be an overhead), still as far as I know it's not illegal to define one.</p>
  
  <p>Anyone else come across this kind of behavior? Is there a way to work around it i.e. define associations using only <code>belongsToMany()</code> and still get the correct table structure for <code>survey_has_questions</code>?</p>