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

Commit 922b7bbb by Mick Hansen

Fix for foreignKey issue in #1685

1 parent 68620db1
...@@ -22,7 +22,7 @@ module.exports = (function() { ...@@ -22,7 +22,7 @@ module.exports = (function() {
if (!this.options.foreignKey) { if (!this.options.foreignKey) {
this.options.foreignKey = Utils._.camelizeIf( this.options.foreignKey = Utils._.camelizeIf(
[ [
Utils._.underscoredIf(this.source.name, this.target.options.underscored), Utils._.underscoredIf(Utils.singularize(this.source.name, this.target.options.language), this.target.options.underscored),
this.source.primaryKeyAttribute this.source.primaryKeyAttribute
].join("_"), ].join("_"),
!this.source.options.underscored !this.source.options.underscored
......
...@@ -453,4 +453,23 @@ describe(Support.getTestDialectTeaser("HasOne"), function() { ...@@ -453,4 +453,23 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
}) })
}) })
describe("Counter part", function () {
describe("BelongsTo", function () {
it('should only generate one foreign key', function () {
var Orders = this.sequelize.define('Orders', {}, {timestamps: false})
, InternetOrders = this.sequelize.define('InternetOrders', {}, {timestamps: false})
InternetOrders.belongsTo(Orders, {
foreignKeyConstraint: true
});
Orders.hasOne(InternetOrders, {
foreignKeyConstraint: true
});
expect(Object.keys(InternetOrders.rawAttributes).length).to.equal(2);
expect(InternetOrders.rawAttributes.OrderId).to.be.ok;
expect(InternetOrders.rawAttributes.OrdersId).not.to.be.ok;
})
})
})
}) })
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!