Node.js Sequelize ManyToMany relations producing incorrect SQL

I'm having a problem with sequelize ManyToMany relations.

Here are my models...

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();

    }

};

Here's the find

db.players.findAll({
    where:      {team_id: 1},
    include:    ['teams']
}).success(function(results) {
    // print the results
});

The above find will produce the following SQL:

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';

What appears to be wrong with this is that the WHERE statement should be WHERE teams.team_id = '1'

Where am I going wrong with this?

Thanks in advance

Hmm actually everything looks quite OK-ish. db.players.findAll with where: { team_id: 1 } should create a query with WHERE players.team_id = '1'. That's perfectly expected. Also, you teams won't have a team_id but an id instead. However, there is a good chance that include is broken atm.