sequelize/sequelize — pull request #698 by jjclark1982 (2013-06-14 12:12:24+00:00)
Title: Fix for many-to-many associations being impossible between models with custom table names

It is currently impossible to create many-to-many associations between DAOs that have custom table names. Consider this example:

```javascript
var Sequelize = require("sequelize");

var sequelize = new Sequelize("db", null, null, {
dialect: "sqlite",
storage: "example.sqlite3"
});

var Listing = sequelize.define("listing", {
"name": {type: Sequelize.STRING}
}, {
tableName: "listings"
});

var Tag = sequelize.define("tag", {
"name": {type: Sequelize.STRING}
}, {
tableName: "tags"
});

Listing.hasMany(Tag, {joinTableName: "listing_has_tags"});
Tag.hasMany(Listing, {joinTableName: "listing_has_tags"});

sequelize.sync();
```

This will try to create an association table with the name `tags` instead of `listing_has_tags`, because the association inherits options from the DAO instead of from the sequelize global options.

I propose fixing this by explicitly setting the association's table name to the combined table name when it is being defined.

It would also be possible to change the way options are inherited in `associations/mixin.js`, but that could change behavior for existing installations.

```javascript
var globalOptions = this.daoFactoryManager.sequelize.options.define
var association = new HasMany(this, associatedDAO, Utils._.extend((options||{}), globalOptions))
```