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

Commit 15f16c40 by Jan Aagaard Meier Committed by GitHub

fix(uniqueConstraintError): Add parent, original and sql properties, similar to …

…other DB errors (#6462)
1 parent adec7184
# Next
- [FIXED] Add `parent`, `original` and `sql` properties to `UniqueConstraintError`
# 3.24.0 # 3.24.0
- [ADDED] `restartIdentity` option for truncate in postgres [#5356](https://github.com/sequelize/sequelize/issues/5356) - [ADDED] `restartIdentity` option for truncate in postgres [#5356](https://github.com/sequelize/sequelize/issues/5356)
......
...@@ -146,6 +146,9 @@ error.UniqueConstraintError = function (options) { ...@@ -146,6 +146,9 @@ error.UniqueConstraintError = function (options) {
this.message = options.message; this.message = options.message;
this.errors = options.errors; this.errors = options.errors;
this.fields = options.fields; this.fields = options.fields;
this.parent = options.parent;
this.original = options.parent;
this.sql = options.parent.sql;
}; };
util.inherits(error.UniqueConstraintError, error.ValidationError); util.inherits(error.UniqueConstraintError, error.ValidationError);
......
...@@ -244,5 +244,25 @@ describe(Support.getTestDialectTeaser('Sequelize Errors'), function () { ...@@ -244,5 +244,25 @@ describe(Support.getTestDialectTeaser('Sequelize Errors'), function () {
return expect(this.sequelize.query('INSERT INTO users (name) VALUES (\'jan\')')).to.be.rejectedWith(this.sequelize.UniqueConstraintError); return expect(this.sequelize.query('INSERT INTO users (name) VALUES (\'jan\')')).to.be.rejectedWith(this.sequelize.UniqueConstraintError);
}); });
}); });
it('adds parent and sql properties', function () {
var User = this.sequelize.define('user', {
name: {
type: Sequelize.STRING,
unique: 'unique',
}
}, { timestamps: false });
return this.sequelize.sync({ force: true }).bind(this).then(function () {
return User.create({ name: 'jan' });
}).then(function () {
return expect(User.create({ name: 'jan' })).to.be.rejected;
}).then(function (error) {
expect(error).to.be.instanceOf(this.sequelize.UniqueConstraintError);
expect(error).to.have.property('parent');
expect(error).to.have.property('original');
expect(error).to.have.property('sql');
});
});
}); });
}); });
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!