domasx2 / sequelize-fixtures

Load data from json, yaml or js to sequelize
301 stars 83 forks source link

belongsToMany association uses the plural form of the table on findOne #62

Open yciabaud opened 8 years ago

yciabaud commented 8 years ago

Hello, I have an issue creating a many to many association with fixtures. In lib/loader.js#L191, assoc.target.findOne is using the plural form of the Team table and therefore the request fails because it cannot find the table.

I don't understand if my model is wrong or if it is an issue in this project.

Can you help me?

Context:

Model:

var User = sequelize.define('User', { [...] });
var Team = sequelize.define('Team', { [...] });

User.belongsToMany(Team, {
  as: 'Teams',
  foreignKey: 'userId',
  through: 'users_teams'
});
Team.belongsToMany(User, {
  as: 'members',
  foreignKey: 'teamId',
  through: 'users_teams'
});

Fixture:

[{
  "model": "User",
  "data": {
    [...],
    "Teams":[{
      [...],
      "_through":"users_teams"
    }]
  }
}]

Resulting SQL request:

SELECT [...] FROM `Teams` AS `Team` WHERE [...] LIMIT 1;
kithokit commented 8 years ago

i am not able to populate the m2m fixtures too