title: Node.js Sequelize ManyToMany relations producing incorrect SQL
body: <p>I'm having a problem with sequelize ManyToMany relations.</p>
  
  <p>Here are my models...</p>
  
  <pre><code>var db = {
  
      players: sequelize.define('players', {
          name: Sequelize.STRING
      }),
  
      teams: sequelize.define('teams', {
          name: Sequelize.STRING
      }),   
  
  
      init: function() {
  
          this.players.hasMany(this.teams, {joinTableName: 'teams_has_players'});
          this.teams.hasMany(this.players, {joinTableName: 'teams_has_players'});
  
          this.players.sync();
          this.teams.sync();
  
      }
  
  };
  </code></pre>
  
  <p>Here's the find</p>
  
  <pre><code>db.players.findAll({
      where:      {team_id: 1},
      include:    ['teams']
  }).success(function(results) {
      // print the results
  });
  </code></pre>
  
  <p>The above find will produce the following SQL:</p>
  
  <pre><code>SELECT 
      players . *,
      teams.name AS `teams.name`,
      teams.id AS `teams.id`
  FROM
      players
          LEFT OUTER JOIN
      teams_has_players ON teams_has_players.player_id = players.id
          LEFT OUTER JOIN
      teams ON teams.id = teams_has_players.team_id
  WHERE
      players.team_id = '1';
  </code></pre>
  
  <p>What appears to be wrong with this is that the WHERE statement should be <code>WHERE teams.team_id = '1'</code></p>
  
  <p>Where am I going wrong with this?</p>
  
  <p>Thanks in advance</p>