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

Commit d61951d6 by Jan Aagaard Meier Committed by GitHub

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

…other DB errors (#6463)
1 parent f89eba1b
......@@ -40,6 +40,7 @@
[#6406](https://github.com/sequelize/sequelize/issues/6406)
- [FIXED] Nested query return correct result when quoteIdentifiers is false. (Postgres) [#6363](https://github.com/sequelize/sequelize/issues/6363)
- [FIXED] Fixed an issue where changing multiple ENUM columns in PostgreSQL could break. [#6203] (https://github.com/sequelize/sequelize/issues/6203)
- [FIXED] Add `parent`, `original` and `sql` properties to `UniqueConstraintError`
## BC breaks:
- Range type bounds now default to [postgres default](https://www.postgresql.org/docs/9.5/static/rangetypes.html#RANGETYPES-CONSTRUCT) `[)` (inclusive, exclusive), previously was `()` (exclusive, exclusive)
......
......@@ -162,6 +162,9 @@ class UniqueConstraintError extends ValidationError {
this.message = options.message;
this.errors = options.errors;
this.fields = options.fields;
this.parent = options.parent;
this.original = options.parent;
this.sql = options.parent.sql;
}
}
exports.UniqueConstraintError = UniqueConstraintError;
......
......@@ -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);
});
});
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!