Updated mysql adapter to support fields that have internal names like "key" or "order"

Updated mysql adapter to support fields that have internal names like
"key" or "order"(they will be escaped to "`key`" and "`order`"), also
added support in case of query generates fields like "table.field" that
will be escaped to "`table`.`field`"
This commit is contained in:
redvulps 2011-11-19 14:40:25 -02:00
parent 3b2b57eb7b
commit abde0df35b
1 changed files with 11 additions and 1 deletions

View File

@ -66,7 +66,17 @@ MySQL.prototype.toFields = function (model, data) {
var props = this._models[model].properties;
Object.keys(data).forEach(function (key) {
if (props[key]) {
fields.push(key + ' = ' + this.toDatabase(props[key], data[key]));
if(key.indexOf('.') != -1) {
keys = key.split('.');
for(var item = 0; item < keys.length; item++) {
keys[item] = '`' + keys[item] + '`';
}
key = keys.join('.');
}
fields.push('`' + key + '` = ' + this.toDatabase(props[key], data[key]));
}
}.bind(this));
return fields.join(',');