ManyToMany 関係の続編に問題があります。
これが私のモデルです...
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();
}
};
これが発見です
db.players.findAll({
where: {team_id: 1},
include: ['teams']
}).success(function(results) {
// print the results
});
上記の検索により、次の 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';
これで間違っているように見えるのは、WHERE ステートメントがWHERE teams.team_id = '1'
これのどこが間違っているのですか?
前もって感謝します