-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4927 from greenify/master
don't overwrite options.foreignKey in associations
- Loading branch information
Showing
6 changed files
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
|
||
/* jshint -W030 */ | ||
var chai = require('chai') | ||
, expect = chai.expect | ||
, Support = require(__dirname + '/../support') | ||
, DataTypes = require(__dirname + '/../../../lib/data-types') | ||
, Sequelize = require('../../../index'); | ||
|
||
describe(Support.getTestDialectTeaser('associations'), function() { | ||
describe('Test options.foreignKey', function() { | ||
beforeEach(function() { | ||
|
||
this.A = this.sequelize.define('A', { | ||
id: { | ||
type: DataTypes.CHAR(20), | ||
primaryKey: true | ||
} | ||
}); | ||
this.B = this.sequelize.define('B', { | ||
id: { | ||
type: Sequelize.CHAR(20), | ||
primaryKey: true | ||
} | ||
}); | ||
this.C = this.sequelize.define('C', {}); | ||
}); | ||
|
||
it('should not be overwritten for belongsTo', function(){ | ||
var reqValidForeignKey = { foreignKey: { allowNull: false }}; | ||
this.A.belongsTo(this.B, reqValidForeignKey); | ||
this.A.belongsTo(this.C, reqValidForeignKey); | ||
expect(this.A.attributes.CId.type).to.deep.equal(this.C.attributes.id.type); | ||
}); | ||
it('should not be overwritten for belongsToMany', function(){ | ||
var reqValidForeignKey = { foreignKey: { allowNull: false }, through: 'ABBridge'}; | ||
this.B.belongsToMany(this.A, reqValidForeignKey); | ||
this.A.belongsTo(this.C, reqValidForeignKey); | ||
expect(this.A.attributes.CId.type).to.deep.equal(this.C.attributes.id.type); | ||
}); | ||
it('should not be overwritten for hasOne', function(){ | ||
var reqValidForeignKey = { foreignKey: { allowNull: false }}; | ||
this.B.hasOne(this.A, reqValidForeignKey); | ||
this.A.belongsTo(this.C, reqValidForeignKey); | ||
expect(this.A.attributes.CId.type).to.deep.equal(this.C.attributes.id.type); | ||
}); | ||
it('should not be overwritten for hasMany', function(){ | ||
var reqValidForeignKey = { foreignKey: { allowNull: false }}; | ||
this.B.hasMany(this.A, reqValidForeignKey); | ||
this.A.belongsTo(this.C, reqValidForeignKey); | ||
expect(this.A.attributes.CId.type).to.deep.equal(this.C.attributes.id.type); | ||
}); | ||
}); | ||
}); |