From e1bd92b52a70cbaaec66cb8669e16476c4881464 Mon Sep 17 00:00:00 2001 From: Dombi Attila Date: Tue, 19 Jun 2012 13:13:59 +0300 Subject: [PATCH 1/3] fix sql error when initializing models with empty Number property. It should return NULL when a number is empty --- lib/adapters/postgres.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/adapters/postgres.js b/lib/adapters/postgres.js index 8bbb8d54..52701e04 100644 --- a/lib/adapters/postgres.js +++ b/lib/adapters/postgres.js @@ -164,7 +164,18 @@ PG.prototype.toDatabase = function (prop, val) { return this.toDatabase(prop, val[0]) + ' AND ' + this.toDatabase(prop, val[1]); } } - if (prop.type.name === 'Number') return val; + if (prop.type.name === 'Number') { + if (!val) { + if( prop.autoIncrement ) { + return 'DEFAULT'; + } + else { + return 'NULL'; + } + } + return val + }; + if (prop.type.name === 'Date') { if (!val) { if( prop.autoIncrement ) { From e4527856ad10794568261bc333d8ab3eecc22e39 Mon Sep 17 00:00:00 2001 From: Dombi Attila Date: Tue, 26 Jun 2012 15:44:57 +0300 Subject: [PATCH 2/3] The updateAttribute callback doesn't behaves as its described. It should send the object instance alongside the error too. --- lib/abstract-class.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/abstract-class.js b/lib/abstract-class.js index bf540321..26863475 100644 --- a/lib/abstract-class.js +++ b/lib/abstract-class.js @@ -577,7 +577,7 @@ AbstractClass.prototype.updateAttributes = function updateAttributes(data, cb) { inst.isValid(function (valid) { if (!valid) { if (cb) { - cb(new Error('Validation error')); + cb(new Error('Validation error'), inst); } } else { update(); From b5eaa99d5abf6ebee529c1d765f86695fe75b4fa Mon Sep 17 00:00:00 2001 From: Dombi Attila Date: Thu, 19 Jul 2012 18:26:58 +0300 Subject: [PATCH 3/3] Added stricter value checking on number. --- lib/adapters/postgres.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/adapters/postgres.js b/lib/adapters/postgres.js index 52701e04..c2f53631 100644 --- a/lib/adapters/postgres.js +++ b/lib/adapters/postgres.js @@ -165,7 +165,7 @@ PG.prototype.toDatabase = function (prop, val) { } } if (prop.type.name === 'Number') { - if (!val) { + if (!val && val!=0) { if( prop.autoIncrement ) { return 'DEFAULT'; }