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 {*}
|
||||
*/
|
||||
MySQL.prototype.fromDatabase = function (model, data) {
|
||||
if (!data) return null;
|
||||
if (!data) {
|
||||
return null;
|
||||
}
|
||||
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];
|
||||
if (typeof val === 'undefined' || val === null) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
if (props[key]) {
|
||||
switch(props[key].type.name) {
|
||||
if (props[p]) {
|
||||
switch(props[p].type.name) {
|
||||
case 'Date':
|
||||
val = new Date(val.toString().replace(/GMT.*$/, 'GMT'));
|
||||
break;
|
||||
|
@ -304,9 +308,9 @@ MySQL.prototype.fromDatabase = function (model, data) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
data[key] = val;
|
||||
});
|
||||
return data;
|
||||
json[p] = val;
|
||||
}
|
||||
return json;
|
||||
};
|
||||
|
||||
MySQL.prototype.escapeName = function (name) {
|
||||
|
@ -428,6 +432,7 @@ function buildLimit(limit, offset) {
|
|||
* @param {Function} [callback] The callback function
|
||||
*/
|
||||
MySQL.prototype.all = function all(model, filter, callback) {
|
||||
var self = this;
|
||||
// Order by id if no order is specified
|
||||
filter = filter || {};
|
||||
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 self = this;
|
||||
|
||||
if (filter) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue