Skip to content

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

@yciabaud

Description

@yciabaud

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:

  • node v6.2.1
  • sequelize@3.24.0

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions