Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yciabaud opened this issue Aug 18, 2016 · 1 comment
Open

Comments

@yciabaud
Copy link

yciabaud commented Aug 18, 2016

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
Copy link

i am not able to populate the m2m fixtures too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants