From ec0a990a2b4552509170f0dbc02c486846732c3a Mon Sep 17 00:00:00 2001 From: Diogo Doreto Date: Fri, 13 Nov 2015 10:08:03 -0200 Subject: [PATCH] Add compatibility with Node v0.12 Node v0.12 doesn't have the Object.assign function --- lib/sql.js | 5 +++-- lib/utils.js | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 lib/utils.js diff --git a/lib/sql.js b/lib/sql.js index ceb94dc..23f576b 100644 --- a/lib/sql.js +++ b/lib/sql.js @@ -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); diff --git a/lib/utils.js b/lib/utils.js new file mode 100644 index 0000000..37e0e57 --- /dev/null +++ b/lib/utils.js @@ -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;