Merge pull request #95 from dombesz/master

Bug on initializing models with empty number property on postgresql.
This commit is contained in:
Anatoliy Chakkaev 2012-09-25 21:19:56 -07:00
commit ab4844b009
2 changed files with 13 additions and 2 deletions

View File

@ -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 File

@ -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 ) {