Fixing some bugs, which fix default values and length of fields in mysql adapter

This commit is contained in:
Amir M. Mahmoudi 2012-02-06 22:22:13 +03:30
parent 04cbad35fd
commit 7569a923c8
1 changed files with 16 additions and 9 deletions

View File

@ -105,7 +105,7 @@ MySQL.prototype.toDatabase = function (prop, val) {
' AND ' +
this.toDatabase(prop, val[1]);
} else if (operator == 'inq' || operator == 'nin') {
if (!(val.propertyIsEnumerable('length')) && typeof val === 'object' && typeof val.length === 'number') { //if value is array
if (!(val.propertyIsEnumerable('length')) && typeof val === 'object' && typeof val.length === 'number') { //if value is array
return val.join(',');
} else {
return val;
@ -413,17 +413,24 @@ MySQL.prototype.propertySettingsSQL = function (model, prop) {
};
function datatype(p) {
var dt = '';
switch (p.type.name) {
case 'String':
return 'VARCHAR(' + (p.limit || 255) + ')';
dt = 'VARCHAR(' + (p.limit || 255) + ')';
break;
case 'Text':
return 'TEXT';
dt = 'TEXT';
break;
case 'Number':
return 'INT(11)';
dt = 'INT(' + (p.limit || 11) + ')';
break;
case 'Date':
return 'DATETIME';
dt = 'DATETIME';
break;
case 'Boolean':
return 'TINYINT(1)';
}
}
dt = 'TINYINT(1)';
break;
}
dt += (typeof p.default !== 'undefined') ? ' DEFAULT ' + p.default.toString() : '';
return dt;
}