Permalink
Browse files

Merge pull request #95 from dombesz/master

Bug on initializing models with empty number property on postgresql.
  • Loading branch information...
2 parents 2cbce0d + b5eaa99 commit ab4844b00995d17369951fb1d5b44aa027c2d724 @1602 committed Sep 26, 2012
Showing with 13 additions and 2 deletions.
  1. +1 −1 lib/abstract-class.js
  2. +12 −1 lib/adapters/postgres.js
View
@@ -606,7 +606,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();
View
@@ -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 && val!=0) {
+ if( prop.autoIncrement ) {
+ return 'DEFAULT';
+ }
+ else {
+ return 'NULL';
+ }
+ }
+ return val
+ };
+
if (prop.type.name === 'Date') {
if (!val) {
if( prop.autoIncrement ) {

0 comments on commit ab4844b

Please sign in to comment.