sequelize/sequelize — pull request #2429 by overlookmotel (2014-10-15 18:38:53+00:00)
Title: Singular through model

PR for https://github.com/sequelize/sequelize/issues/2415

When a through table model is auto-created in defining a many-to-many association, the current behaviour is for the model's name to be pluralized and the same as the table name. This behaviour is at odds with the general Sequelize convention of singular model names and plural table names.

This PR changes that behaviour to make the model names singular.

So now:

Person.hasMany(Task);
Task.hasMany(Person);

creates a through model called `PersonTask` with table name `PeopleTasks`.

When retrieving a many-to-many associated table using eager-loading, the attributes of the join table are available in a key named the same as the through model (i.e. singular). It used to be plural, which makes little sense since there is only a single row.

e.g.

Person.findAll( { include: Task } )

returns:

[ {
name: 'Bob',
Tasks: [ {
name: 'Do the washing',
PersonTask: { ... }
} ]
} ]

This PR also fixes a few places in the code where the table name was used where it should have been the model name.