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

Commit 3c34a623 by vvo

update postgresql error message parsing on foreign key

Error code: 23503

On "recent" postgresql (> 8?), error message is:
insert or update on table "$table" violates foreign key constraint
"$index"

I updated the error match to get the right table and index in both
cases.

Before this patch, sequelize failed badly with: `TypeError: Cannot read
property '1' of null`
1 parent fc064294
Showing with 8 additions and 4 deletions
......@@ -240,15 +240,19 @@ module.exports = (function() {
};
Query.prototype.formatError = function (err) {
var match;
var match
, table
, index;
switch (err.code) {
case '23503':
match = err.message.match(/violates foreign key constraint \"(.+?)\" on table \"(.+?)\"/);
index = err.message.match(/violates foreign key constraint \"(.+?)\"/)[1];
table = err.message.match(/on table \"(.+?)\"/)[1];
return new sequelizeErrors.ForeignKeyConstraintError({
fields: null,
index: match[1],
table: match[2],
index: index,
table: table,
parent: err
});
case '23505':
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!