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

Commit 8d2bb59a by Jan Aagaard Meier

Changed useConstraints to constraints

1 parent 4ae1e833
...@@ -47,7 +47,7 @@ module.exports = (function() { ...@@ -47,7 +47,7 @@ module.exports = (function() {
var newAttributes = {} var newAttributes = {}
newAttributes[this.identifier] = { type: this.options.keyType || this.target.rawAttributes[this.targetIdentifier].type } newAttributes[this.identifier] = { type: this.options.keyType || this.target.rawAttributes[this.targetIdentifier].type }
if (this.options.useConstraints !== false) { if (this.options.constraints !== false) {
this.options.onDelete = this.options.onDelete || 'SET NULL' this.options.onDelete = this.options.onDelete || 'SET NULL'
this.options.onUpdate = this.options.onUpdate || 'CASCADE' this.options.onUpdate = this.options.onUpdate || 'CASCADE'
} }
......
...@@ -180,13 +180,13 @@ module.exports = (function() { ...@@ -180,13 +180,13 @@ module.exports = (function() {
, sourceAttribute = { type: sourceKeyType } , sourceAttribute = { type: sourceKeyType }
, targetAttribute = { type: targetKeyType } , targetAttribute = { type: targetKeyType }
if (this.options.useConstraints !== false) { if (this.options.constraints !== false) {
sourceAttribute.references = this.source.getTableName() sourceAttribute.references = this.source.getTableName()
sourceAttribute.referencesKey = this.source.primaryKeyAttribute sourceAttribute.referencesKey = this.source.primaryKeyAttribute
sourceAttribute.onDelete = this.options.onDelete || 'CASCADE' sourceAttribute.onDelete = this.options.onDelete || 'CASCADE'
sourceAttribute.onUpdate = this.options.onUpdate || 'CASCADE' sourceAttribute.onUpdate = this.options.onUpdate || 'CASCADE'
} }
if (this.targetAssociation.options.useConstraints !== false) { if (this.targetAssociation.options.constraints !== false) {
targetAttribute.references = this.target.getTableName() targetAttribute.references = this.target.getTableName()
targetAttribute.referencesKey = this.target.primaryKeyAttribute targetAttribute.referencesKey = this.target.primaryKeyAttribute
targetAttribute.onDelete = this.targetAssociation.options.onDelete || 'CASCADE' targetAttribute.onDelete = this.targetAssociation.options.onDelete || 'CASCADE'
...@@ -210,7 +210,7 @@ module.exports = (function() { ...@@ -210,7 +210,7 @@ module.exports = (function() {
var constraintOptions = _.clone(this.options) // Create a new options object for use with addForeignKeyConstraints, to avoid polluting this.options in case it is later used for a n:m var constraintOptions = _.clone(this.options) // Create a new options object for use with addForeignKeyConstraints, to avoid polluting this.options in case it is later used for a n:m
newAttributes[this.identifier] = { type: this.options.keyType || this.target.rawAttributes[this.target.primaryKeyAttribute].type } newAttributes[this.identifier] = { type: this.options.keyType || this.target.rawAttributes[this.target.primaryKeyAttribute].type }
if (this.options.useConstraints !== false) { if (this.options.constraints !== false) {
constraintOptions.onDelete = constraintOptions.onDelete || 'SET NULL' constraintOptions.onDelete = constraintOptions.onDelete || 'SET NULL'
constraintOptions.onUpdate = constraintOptions.onUpdate || 'CASCADE' constraintOptions.onUpdate = constraintOptions.onUpdate || 'CASCADE'
} }
......
...@@ -49,7 +49,7 @@ module.exports = (function() { ...@@ -49,7 +49,7 @@ module.exports = (function() {
newAttributes[this.identifier] = { type: this.options.keyType || keyType } newAttributes[this.identifier] = { type: this.options.keyType || keyType }
Utils._.defaults(this.target.rawAttributes, newAttributes) Utils._.defaults(this.target.rawAttributes, newAttributes)
if (this.options.useConstraints !== false) { if (this.options.constraints !== false) {
this.options.onDelete = this.options.onDelete || 'SET NULL' this.options.onDelete = this.options.onDelete || 'SET NULL'
this.options.onUpdate = this.options.onUpdate || 'CASCADE' this.options.onUpdate = this.options.onUpdate || 'CASCADE'
} }
......
...@@ -309,7 +309,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() { ...@@ -309,7 +309,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
var Task = this.sequelize.define('Task', { title: Sequelize.STRING }) var Task = this.sequelize.define('Task', { title: Sequelize.STRING })
, User = this.sequelize.define('User', { username: Sequelize.STRING }) , User = this.sequelize.define('User', { username: Sequelize.STRING })
Task.belongsTo(User, { useConstraints: false }) Task.belongsTo(User, { constraints: false })
this.sequelize.sync({ force: true }).success(function() { this.sequelize.sync({ force: true }).success(function() {
User.create({ username: 'foo' }).success(function(user) { User.create({ username: 'foo' }).success(function(user) {
...@@ -469,7 +469,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() { ...@@ -469,7 +469,7 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
var tableName = 'TaskXYZ_' + dataType.toString() var tableName = 'TaskXYZ_' + dataType.toString()
Tasks[dataType] = self.sequelize.define(tableName, { title: DataTypes.STRING }) Tasks[dataType] = self.sequelize.define(tableName, { title: DataTypes.STRING })
Tasks[dataType].belongsTo(User, { foreignKey: 'userId', keyType: dataType, useConstraints: false }) Tasks[dataType].belongsTo(User, { foreignKey: 'userId', keyType: dataType, constraints: false })
}) })
self.sequelize.sync({ force: true }) self.sequelize.sync({ force: true })
......
...@@ -1423,7 +1423,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1423,7 +1423,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
var Task = this.sequelize.define('Task', { title: DataTypes.STRING }) var Task = this.sequelize.define('Task', { title: DataTypes.STRING })
, User = this.sequelize.define('User', { username: DataTypes.STRING }) , User = this.sequelize.define('User', { username: DataTypes.STRING })
User.hasMany(Task, { useConstraints: false }) User.hasMany(Task, { constraints: false })
this.sequelize.sync({ force: true }).success(function() { this.sequelize.sync({ force: true }).success(function() {
User.create({ username: 'foo' }).success(function(user) { User.create({ username: 'foo' }).success(function(user) {
...@@ -1669,8 +1669,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1669,8 +1669,8 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
var _done = _.after(2, done) var _done = _.after(2, done)
, self = this , self = this
self.User.hasMany(self.Task, { useConstraints: false }) self.User.hasMany(self.Task, { constraints: false })
self.Task.hasMany(self.User, { useConstraints: false }) self.Task.hasMany(self.User, { constraints: false })
this.sequelize.sync({ force: true }).success(function() { this.sequelize.sync({ force: true }).success(function() {
self.User.create({ id: 67, username: 'foo' }).success(function(user) { self.User.create({ id: 67, username: 'foo' }).success(function(user) {
...@@ -1716,7 +1716,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -1716,7 +1716,7 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
var tableName = 'TaskXYZ_' + dataType.toString() var tableName = 'TaskXYZ_' + dataType.toString()
Tasks[dataType] = self.sequelize.define(tableName, { title: DataTypes.STRING }) Tasks[dataType] = self.sequelize.define(tableName, { title: DataTypes.STRING })
User.hasMany(Tasks[dataType], { foreignKey: 'userId', keyType: dataType, useConstraints: false }) User.hasMany(Tasks[dataType], { foreignKey: 'userId', keyType: dataType, constraints: false })
Tasks[dataType].sync({ force: true }).success(function() { Tasks[dataType].sync({ force: true }).success(function() {
expect(Tasks[dataType].rawAttributes.userId.type.toString()) expect(Tasks[dataType].rawAttributes.userId.type.toString())
......
...@@ -258,7 +258,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() { ...@@ -258,7 +258,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
var Task = this.sequelize.define('Task', { title: Sequelize.STRING }) var Task = this.sequelize.define('Task', { title: Sequelize.STRING })
, User = this.sequelize.define('User', { username: Sequelize.STRING }) , User = this.sequelize.define('User', { username: Sequelize.STRING })
User.hasOne(Task, { useConstraints: false }) User.hasOne(Task, { constraints: false })
User.sync({ force: true }).success(function() { User.sync({ force: true }).success(function() {
Task.sync({ force: true }).success(function() { Task.sync({ force: true }).success(function() {
...@@ -429,7 +429,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() { ...@@ -429,7 +429,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
var tableName = 'TaskXYZ_' + dataType.toString() var tableName = 'TaskXYZ_' + dataType.toString()
Tasks[dataType] = self.sequelize.define(tableName, { title: Sequelize.STRING }) Tasks[dataType] = self.sequelize.define(tableName, { title: Sequelize.STRING })
User.hasOne(Tasks[dataType], { foreignKey: 'userId', keyType: dataType, useConstraints: false }) User.hasOne(Tasks[dataType], { foreignKey: 'userId', keyType: dataType, constraints: false })
Tasks[dataType].sync({ force: true }).success(function() { Tasks[dataType].sync({ force: true }).success(function() {
expect(Tasks[dataType].rawAttributes.userId.type.toString()) expect(Tasks[dataType].rawAttributes.userId.type.toString())
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!