不要怂,就是干,撸起袖子干!

Commit 8b234bf3 by Jan Aagaard Meier

Merge pull request #698 from jjclark1982/master

Fix for many-to-many associations being impossible between models with custom table names
2 parents 9a160daf 0b1216e3
......@@ -19,6 +19,7 @@ module.exports = (function() {
this.isSelfAssociation ? (this.options.as || this.target.tableName) : this.target.tableName
)
this.associationAccessor = this.combinedName = (this.options.joinTableName || combinedTableName)
this.options.tableName = this.combinedName
var as = (this.options.as || Utils.pluralize(this.target.tableName))
......
......@@ -415,6 +415,42 @@ describe(Helpers.getTestDialectTeaser("HasMany"), function() {
}.bind(this))
})
}) // end optimization using bulk create, destroy and update
describe('join table creation', function () {
before(function (done) {
this.User = this.sequelize.define('User',
{ username: Sequelize.STRING },
{ tableName: 'users'}
)
this.Task = this.sequelize.define('Task',
{ title: Sequelize.STRING },
{ tableName: 'tasks' }
)
this.User.hasMany(this.Task,
{ joinTableName: 'user_has_tasks' }
)
this.Task.hasMany(this.User)
this.sequelize.sync({force: true}).success(done)
})
it('uses the specified joinTableName or a reasonable default', function(done) {
for (var associationName in this.User.associations) {
expect(associationName).not.toEqual(this.User.tableName)
var joinTableName = this.User.associations[associationName].options.joinTableName
if (typeof joinTableName !== 'undefined') {
expect(joinTableName).toEqual(associationName)
}
var tableName = this.User.associations[associationName].options.tableName
if (typeof tableName !== 'undefined') {
expect(tableName).toEqual(associationName)
}
}
done()
})
})
})
describe("Foreign key constraints", function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!