Fix the property mapping for return values
This commit is contained in:
parent
2a0970317a
commit
20305878d2
22
lib/mysql.js
22
lib/mysql.js
|
@ -280,15 +280,19 @@ MySQL.prototype.toDatabase = function (prop, val) {
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
MySQL.prototype.fromDatabase = function (model, data) {
|
MySQL.prototype.fromDatabase = function (model, data) {
|
||||||
if (!data) return null;
|
if (!data) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
var props = this._models[model].properties;
|
var props = this._models[model].properties;
|
||||||
Object.keys(data).forEach(function (key) {
|
var json = {};
|
||||||
|
for(var p in props) {
|
||||||
|
var key = this.column(model, p);
|
||||||
var val = data[key];
|
var val = data[key];
|
||||||
if (typeof val === 'undefined' || val === null) {
|
if (typeof val === 'undefined' || val === null) {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
if (props[key]) {
|
if (props[p]) {
|
||||||
switch(props[key].type.name) {
|
switch(props[p].type.name) {
|
||||||
case 'Date':
|
case 'Date':
|
||||||
val = new Date(val.toString().replace(/GMT.*$/, 'GMT'));
|
val = new Date(val.toString().replace(/GMT.*$/, 'GMT'));
|
||||||
break;
|
break;
|
||||||
|
@ -304,9 +308,9 @@ MySQL.prototype.fromDatabase = function (model, data) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data[key] = val;
|
json[p] = val;
|
||||||
});
|
}
|
||||||
return data;
|
return json;
|
||||||
};
|
};
|
||||||
|
|
||||||
MySQL.prototype.escapeName = function (name) {
|
MySQL.prototype.escapeName = function (name) {
|
||||||
|
@ -428,6 +432,7 @@ function buildLimit(limit, offset) {
|
||||||
* @param {Function} [callback] The callback function
|
* @param {Function} [callback] The callback function
|
||||||
*/
|
*/
|
||||||
MySQL.prototype.all = function all(model, filter, callback) {
|
MySQL.prototype.all = function all(model, filter, callback) {
|
||||||
|
var self = this;
|
||||||
// Order by id if no order is specified
|
// Order by id if no order is specified
|
||||||
filter = filter || {};
|
filter = filter || {};
|
||||||
if(!filter.order) {
|
if(!filter.order) {
|
||||||
|
@ -438,7 +443,6 @@ MySQL.prototype.all = function all(model, filter, callback) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var sql = 'SELECT '+ this.getColumns(model, filter.fields) + ' FROM ' + this.tableEscaped(model);
|
var sql = 'SELECT '+ this.getColumns(model, filter.fields) + ' FROM ' + this.tableEscaped(model);
|
||||||
var self = this;
|
|
||||||
|
|
||||||
if (filter) {
|
if (filter) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue