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

Commit 798ecb12 by Mick Hansen

fix(hasMany): fix foreign key naming issue with N:M (closes #1685)

1 parent 922b7bbb
......@@ -138,7 +138,10 @@ module.exports = (function() {
, primaryKeyDeleted = false
this.identifier = this.options.foreignKey || Utils._.camelizeIf(
[Utils.singularize(this.source.name, this.source.options.language), this.source.primaryKeyAttribute].join("_"),
[
Utils._.underscoredIf(Utils.singularize(this.source.name, this.source.options.language), this.source.options.underscored),
this.source.primaryKeyAttribute
].join("_"),
!this.source.options.underscored
)
......
......@@ -1036,6 +1036,34 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
})
})
describe('foreign keys', function () {
it('should correctly generate underscored keys', function () {
var User = this.sequelize.define('User', {
}, {
tableName: 'users',
underscored: true,
timestamps: false
})
var Place = this.sequelize.define('Place', {
//fields
},{
tableName: 'places',
underscored: true,
timestamps: false
});
User.hasMany(Place, { joinTableName: 'user_places' });
Place.hasMany(User, { joinTableName: 'user_places' });
var attributes = this.sequelize.model('user_places').rawAttributes;
expect(attributes.place_id).to.be.ok
expect(attributes.user_id).to.be.ok
})
})
describe('primary key handling for join table', function () {
beforeEach(function (done) {
this.User = this.sequelize.define('User',
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!