Add compatibility with Node v0.12

Node v0.12 doesn't have the Object.assign function
This commit is contained in:
Diogo Doreto 2015-11-13 10:08:03 -02:00
parent 68264d59ab
commit ec0a990a2b
2 changed files with 21 additions and 2 deletions

View File

@ -5,6 +5,7 @@ var Connector = require('./connector');
var debug = require('debug')('loopback:connector:sql');
var ParameterizedSQL = require('./parameterized-sql');
var Transaction = require('./transaction');
var assign = require('./utils').assign;
module.exports = SQLConnector;
@ -1067,10 +1068,10 @@ SQLConnector.prototype.buildJoins = function(model, where) {
var modelToEscaped = this.tableEscaped(modelTo);
var keyTo = rel.keyTo;
var innerWhere = Object.assign({}, where[key]);
var innerWhere = assign({}, where[key]);
var innerIdField = {};
innerIdField[keyTo] = true;
innerWhere.fields = Object.assign({}, innerWhere.fields, innerIdField);
innerWhere.fields = assign({}, innerWhere.fields, innerIdField);
var condition = this.columnEscaped(model, keyFrom) + '=' +
this.columnEscaped(modelTo, keyTo);

18
lib/utils.js Normal file
View File

@ -0,0 +1,18 @@
var _hasOwnProp = Object.prototype.hasOwnProperty;
/**
* Object.assign polyfill
*/
var assign = Object.assign || function(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (_hasOwnProp.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
exports.assign = assign;