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

Commit dd3cd4be by Mick Hansen

fix some foreign key cases

1 parent 5933bc89
......@@ -22,7 +22,10 @@ module.exports = (function() {
if (!this.options.foreignKey) {
this.options.foreignKey = Utils._.camelizeIf(
[this.as, this.target.primaryKeyAttribute].join("_"),
[
Utils._.underscoredIf(this.as, this.source.options.underscored),
this.target.primaryKeyAttribute
].join("_"),
!this.source.options.underscored
)
}
......
......@@ -21,7 +21,10 @@ module.exports = (function() {
if (!this.options.foreignKey) {
this.options.foreignKey = Utils._.camelizeIf(
[this.source.name, this.source.primaryKeyAttribute].join("_"),
[
Utils._.underscoredIf(this.source.name, this.target.options.underscored),
this.source.primaryKeyAttribute
].join("_"),
!this.source.options.underscored
)
}
......
......@@ -238,7 +238,26 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
})
})
describe("Foreign key constraints", function() {
describe("foreign key", function () {
it('should lowercase foreign keys when using underscored', function () {
var User = this.sequelize.define('User', { username: Sequelize.STRING }, { underscored: true })
, Account = this.sequelize.define('Account', { name: Sequelize.STRING }, { underscored: true })
User.belongsTo(Account)
expect(User.rawAttributes.account_id).to.exist;
});
it('should use model name when using camelcase', function () {
var User = this.sequelize.define('User', { username: Sequelize.STRING }, { underscored: false })
, Account = this.sequelize.define('Account', { name: Sequelize.STRING }, { underscored: false })
User.belongsTo(Account)
expect(User.rawAttributes.AccountId).to.exist;
});
});
describe("foreign key constraints", function() {
it("are not enabled by default", function(done) {
var Task = this.sequelize.define('Task', { title: DataTypes.STRING })
, User = this.sequelize.define('User', { username: DataTypes.STRING })
......
......@@ -211,7 +211,26 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
})
})
describe("Foreign key constraints", function() {
describe("foreign key", function () {
it('should lowercase foreign keys when using underscored', function () {
var User = this.sequelize.define('User', { username: Sequelize.STRING }, { underscored: true })
, Account = this.sequelize.define('Account', { name: Sequelize.STRING }, { underscored: true })
Account.hasOne(User)
expect(User.rawAttributes.account_id).to.exist
})
it('should use model name when using camelcase', function () {
var User = this.sequelize.define('User', { username: Sequelize.STRING }, { underscored: false })
, Account = this.sequelize.define('Account', { name: Sequelize.STRING }, { underscored: false })
Account.hasOne(User)
expect(User.rawAttributes.AccountId).to.exist
})
})
describe("foreign key constraints", function() {
it("are not enabled by default", function(done) {
var Task = this.sequelize.define('Task', { title: Sequelize.STRING })
, User = this.sequelize.define('User', { username: Sequelize.STRING })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!