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

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() { ...@@ -497,35 +497,38 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
} }
it("can cascade updates", function(done) { // NOTE: mssql does not support changing an autoincrement primary key
var Task = this.sequelize.define('Task', { title: DataTypes.STRING }) if (dialect !== 'mssql') {
, User = this.sequelize.define('User', { username: DataTypes.STRING }) 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() { this.sequelize.sync({ force: true }).success(function() {
User.create({ username: 'foo' }).success(function(user) { User.create({ username: 'foo' }).success(function(user) {
Task.create({ title: 'task' }).success(function(task) { Task.create({ title: 'task' }).success(function(task) {
task.setUser(user).success(function() { task.setUser(user).success(function() {
// Changing the id of a DAO requires a little dance since // Changing the id of a DAO requires a little dance since
// the `UPDATE` query generated by `save()` uses `id` in the // the `UPDATE` query generated by `save()` uses `id` in the
// `WHERE` clause // `WHERE` clause
var tableName = user.QueryInterface.QueryGenerator.addSchema(user.Model) var tableName = user.QueryInterface.QueryGenerator.addSchema(user.Model)
user.QueryInterface.update(user, tableName, {id: 999}, user.id) user.QueryInterface.update(user, tableName, {id: 999}, user.id)
.success(function() { .success(function() {
Task.findAll().success(function(tasks) { Task.findAll().success(function(tasks) {
expect(tasks).to.have.length(1) expect(tasks).to.have.length(1)
expect(tasks[0].UserId).to.equal(999) expect(tasks[0].UserId).to.equal(999)
done() done()
})
}) })
}) })
}) })
}) })
}) })
}) })
}) }
}) })
......
...@@ -2329,33 +2329,36 @@ describe(Support.getTestDialectTeaser("HasMany"), function() { ...@@ -2329,33 +2329,36 @@ describe(Support.getTestDialectTeaser("HasMany"), function() {
}); });
}); });
it("can cascade updates", function() { // NOTE: mssql does not support changing an autoincrement primary key
var Task = this.sequelize.define('Task', { title: DataTypes.STRING }) if (dialect !== 'mssql') {
, User = this.sequelize.define('User', { username: DataTypes.STRING }); 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 this.sequelize.sync({ force: true }).then(function () {
return Promise.all([ return Promise.all([
User.create({ username: 'foo' }), User.create({ username: 'foo' }),
Task.create({ title: 'task' }), Task.create({ title: 'task' }),
]); ]);
}).spread(function (user, task) { }).spread(function (user, task) {
return user.setTasks([task]).return(user); return user.setTasks([task]).return(user);
}).then(function(user) { }).then(function(user) {
// Changing the id of a DAO requires a little dance since // Changing the id of a DAO requires a little dance since
// the `UPDATE` query generated by `save()` uses `id` in the // the `UPDATE` query generated by `save()` uses `id` in the
// `WHERE` clause // `WHERE` clause
var tableName = user.QueryInterface.QueryGenerator.addSchema(user.Model); var tableName = user.QueryInterface.QueryGenerator.addSchema(user.Model);
return user.QueryInterface.update(user, tableName, {id: 999}, user.id); return user.QueryInterface.update(user, tableName, {id: 999}, user.id);
}).then(function() { }).then(function() {
return Task.findAll(); return Task.findAll();
}).then(function(tasks) { }).then(function(tasks) {
expect(tasks).to.have.length(1); expect(tasks).to.have.length(1);
expect(tasks[0].UserId).to.equal(999); expect(tasks[0].UserId).to.equal(999);
});
}); });
}); }
if (current.dialect.supports.constraints.restrict) { if (current.dialect.supports.constraints.restrict) {
it("can restrict deletes", function() { it("can restrict deletes", function() {
......
...@@ -395,29 +395,32 @@ describe(Support.getTestDialectTeaser("HasOne"), function() { ...@@ -395,29 +395,32 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
}) })
}) })
it("can cascade updates", function(done) { // NOTE: mssql does not support changing an autoincrement primary key
var Task = this.sequelize.define('Task', { title: Sequelize.STRING }) if (dialect !== 'mssql') {
, User = this.sequelize.define('User', { username: Sequelize.STRING }) 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() { User.sync({ force: true }).success(function() {
Task.sync({ force: true }).success(function() { Task.sync({ force: true }).success(function() {
User.create({ username: 'foo' }).success(function(user) { User.create({ username: 'foo' }).success(function(user) {
Task.create({ title: 'task' }).success(function(task) { Task.create({ title: 'task' }).success(function(task) {
user.setTask(task).success(function() { user.setTask(task).success(function() {
// Changing the id of a DAO requires a little dance since // Changing the id of a DAO requires a little dance since
// the `UPDATE` query generated by `save()` uses `id` in the // the `UPDATE` query generated by `save()` uses `id` in the
// `WHERE` clause // `WHERE` clause
var tableName = user.QueryInterface.QueryGenerator.addSchema(user.Model) var tableName = user.QueryInterface.QueryGenerator.addSchema(user.Model)
user.QueryInterface.update(user, tableName, {id: 999}, user.id) user.QueryInterface.update(user, tableName, {id: 999}, user.id)
.success(function() { .success(function() {
Task.findAll().success(function(tasks) { Task.findAll().success(function(tasks) {
expect(tasks).to.have.length(1) expect(tasks).to.have.length(1)
expect(tasks[0].UserId).to.equal(999) expect(tasks[0].UserId).to.equal(999)
done() done()
})
}) })
}) })
}) })
...@@ -425,7 +428,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() { ...@@ -425,7 +428,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
}) })
}) })
}) })
}) }
if (current.dialect.supports.constraints.restrict) { 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!