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

Commit e1052290 by Matt Broadstone

mssql does not support updating an identity primary key

These tests must be disabled since MSSQL simply doesn't allow
the updating of these types of fields. Cascading updates are supported
and should be covered by other tests.
1 parent e936f9f0
......@@ -497,35 +497,38 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
}
it("can cascade updates", function(done) {
var Task = this.sequelize.define('Task', { title: DataTypes.STRING })
, User = this.sequelize.define('User', { username: DataTypes.STRING })
// NOTE: mssql does not support changing an autoincrement primary key
if (dialect !== 'mssql') {
it("can cascade updates", function(done) {
var Task = this.sequelize.define('Task', { title: DataTypes.STRING })
, User = this.sequelize.define('User', { username: DataTypes.STRING })
Task.belongsTo(User, {onUpdate: 'cascade'})
Task.belongsTo(User, {onUpdate: 'cascade'})
this.sequelize.sync({ force: true }).success(function() {
User.create({ username: 'foo' }).success(function(user) {
Task.create({ title: 'task' }).success(function(task) {
task.setUser(user).success(function() {
this.sequelize.sync({ force: true }).success(function() {
User.create({ username: 'foo' }).success(function(user) {
Task.create({ title: 'task' }).success(function(task) {
task.setUser(user).success(function() {
// Changing the id of a DAO requires a little dance since
// the `UPDATE` query generated by `save()` uses `id` in the
// `WHERE` clause
// Changing the id of a DAO requires a little dance since
// the `UPDATE` query generated by `save()` uses `id` in the
// `WHERE` clause
var tableName = user.QueryInterface.QueryGenerator.addSchema(user.Model)
user.QueryInterface.update(user, tableName, {id: 999}, user.id)
.success(function() {
Task.findAll().success(function(tasks) {
expect(tasks).to.have.length(1)
expect(tasks[0].UserId).to.equal(999)
done()
var tableName = user.QueryInterface.QueryGenerator.addSchema(user.Model)
user.QueryInterface.update(user, tableName, {id: 999}, user.id)
.success(function() {
Task.findAll().success(function(tasks) {
expect(tasks).to.have.length(1)
expect(tasks[0].UserId).to.equal(999)
done()
})
})
})
})
})
})
})
})
}
})
......
......@@ -2329,33 +2329,36 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
});
});
it("can cascade updates", function() {
var Task = this.sequelize.define('Task', { title: DataTypes.STRING })
, User = this.sequelize.define('User', { username: DataTypes.STRING });
// NOTE: mssql does not support changing an autoincrement primary key
if (dialect !== 'mssql') {
it("can cascade updates", function() {
var Task = this.sequelize.define('Task', { title: DataTypes.STRING })
, User = this.sequelize.define('User', { username: DataTypes.STRING });
User.hasMany(Task, {onUpdate: 'cascade'});
User.hasMany(Task, {onUpdate: 'cascade'});
return this.sequelize.sync({ force: true }).then(function () {
return Promise.all([
User.create({ username: 'foo' }),
Task.create({ title: 'task' }),
]);
}).spread(function (user, task) {
return user.setTasks([task]).return(user);
}).then(function(user) {
// Changing the id of a DAO requires a little dance since
// the `UPDATE` query generated by `save()` uses `id` in the
// `WHERE` clause
return this.sequelize.sync({ force: true }).then(function () {
return Promise.all([
User.create({ username: 'foo' }),
Task.create({ title: 'task' }),
]);
}).spread(function (user, task) {
return user.setTasks([task]).return(user);
}).then(function(user) {
// Changing the id of a DAO requires a little dance since
// the `UPDATE` query generated by `save()` uses `id` in the
// `WHERE` clause
var tableName = user.QueryInterface.QueryGenerator.addSchema(user.Model);
return user.QueryInterface.update(user, tableName, {id: 999}, user.id);
}).then(function() {
return Task.findAll();
}).then(function(tasks) {
expect(tasks).to.have.length(1);
expect(tasks[0].UserId).to.equal(999);
var tableName = user.QueryInterface.QueryGenerator.addSchema(user.Model);
return user.QueryInterface.update(user, tableName, {id: 999}, user.id);
}).then(function() {
return Task.findAll();
}).then(function(tasks) {
expect(tasks).to.have.length(1);
expect(tasks[0].UserId).to.equal(999);
});
});
});
}
if (current.dialect.supports.constraints.restrict) {
it("can restrict deletes", function() {
......
......@@ -395,29 +395,32 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
})
})
it("can cascade updates", function(done) {
var Task = this.sequelize.define('Task', { title: Sequelize.STRING })
, User = this.sequelize.define('User', { username: Sequelize.STRING })
// NOTE: mssql does not support changing an autoincrement primary key
if (dialect !== 'mssql') {
it("can cascade updates", function(done) {
var Task = this.sequelize.define('Task', { title: Sequelize.STRING })
, User = this.sequelize.define('User', { username: Sequelize.STRING })
User.hasOne(Task, {onUpdate: 'cascade'})
User.hasOne(Task, {onUpdate: 'cascade'})
User.sync({ force: true }).success(function() {
Task.sync({ force: true }).success(function() {
User.create({ username: 'foo' }).success(function(user) {
Task.create({ title: 'task' }).success(function(task) {
user.setTask(task).success(function() {
User.sync({ force: true }).success(function() {
Task.sync({ force: true }).success(function() {
User.create({ username: 'foo' }).success(function(user) {
Task.create({ title: 'task' }).success(function(task) {
user.setTask(task).success(function() {
// Changing the id of a DAO requires a little dance since
// the `UPDATE` query generated by `save()` uses `id` in the
// `WHERE` clause
// Changing the id of a DAO requires a little dance since
// the `UPDATE` query generated by `save()` uses `id` in the
// `WHERE` clause
var tableName = user.QueryInterface.QueryGenerator.addSchema(user.Model)
user.QueryInterface.update(user, tableName, {id: 999}, user.id)
.success(function() {
Task.findAll().success(function(tasks) {
expect(tasks).to.have.length(1)
expect(tasks[0].UserId).to.equal(999)
done()
var tableName = user.QueryInterface.QueryGenerator.addSchema(user.Model)
user.QueryInterface.update(user, tableName, {id: 999}, user.id)
.success(function() {
Task.findAll().success(function(tasks) {
expect(tasks).to.have.length(1)
expect(tasks[0].UserId).to.equal(999)
done()
})
})
})
})
......@@ -425,7 +428,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
})
})
})
})
}
if (current.dialect.supports.constraints.restrict) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!