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

Commit 62a57a01 by Harshith Kashyap Committed by Sushant

[MSSQL] Format Merge Statement foreignKey violation as ForeignKeyConstraintError (#7024)

* [MSSQL] MERGE statement foreignKey violation is formatted as ForeignKeyConstraintError, Closes #7011

* Added changelog entry

* Alter changelog entry

* [ci skip] link to issue
1 parent f1762fd8
# Future
- [FIXED] Throw MSSQL MERGE Statement foreignKey violations as ForeignKeyConstraintError [#7011](https://github.com/sequelize/sequelize/pull/7011)
- [FIXED] Transaction Name too long, transaction savepoints for SQL Server [#6972](https://github.com/sequelize/sequelize/pull/6972)
- [FIXED] Issue with sync hooks (before/afterInit, before/afterDefine) [#6680](https://github.com/sequelize/sequelize/issues/6680)
- [FIXED] MSSQL handle large bulk inserts [#6866](https://github.com/sequelize/sequelize/issues/6866)
......
......@@ -246,6 +246,7 @@ class Query extends AbstractQuery {
match = err.message.match(/Failed on step '(.*)'.Could not create constraint. See previous errors./) ||
err.message.match(/The DELETE statement conflicted with the REFERENCE constraint "(.*)". The conflict occurred in database "(.*)", table "(.*)", column '(.*)'./) ||
err.message.match(/The INSERT statement conflicted with the FOREIGN KEY constraint "(.*)". The conflict occurred in database "(.*)", table "(.*)", column '(.*)'./) ||
err.message.match(/The MERGE statement conflicted with the FOREIGN KEY constraint "(.*)". The conflict occurred in database "(.*)", table "(.*)", column '(.*)'./) ||
err.message.match(/The UPDATE statement conflicted with the FOREIGN KEY constraint "(.*)". The conflict occurred in database "(.*)", table "(.*)", column '(.*)'./);
if (match && match.length > 0) {
return new sequelizeErrors.ForeignKeyConstraintError({
......
......@@ -389,6 +389,30 @@ describe(Support.getTestDialectTeaser('Model'), function() {
});
});
});
if (dialect === 'mssql') {
it('Should throw foreignKey violation for MERGE statement as ForeignKeyConstraintError', function () {
const User = this.sequelize.define('User', {
username: {
type: DataTypes.STRING,
primaryKey: true
}
});
const Posts = this.sequelize.define('Posts', {
title: {
type: DataTypes.STRING,
primaryKey: true
},
username: DataTypes.STRING
});
Posts.belongsTo(User, { foreignKey: 'username' });
return this.sequelize.sync({ force: true })
.then(() => User.create({ username: 'user1' }))
.then(() => {
return expect(Posts.upsert({ title: 'Title', username: 'user2' })).to.eventually.be.rejectedWith(Sequelize.ForeignKeyConstraintError);
});
});
}
});
}
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!