diff --git a/lib/sql.js b/lib/sql.js index ba3c3af7..4f07a6bc 100644 --- a/lib/sql.js +++ b/lib/sql.js @@ -562,7 +562,7 @@ SQLConnector.prototype.buildInsertAll = function(model, data, options) { return null; } const fieldsArray = this.buildFieldsFromArray(model, data); - if (fieldsArray.length === 0) { + if (Array.isArray(fieldsArray) && fieldsArray.length === 0) { debug('no fields found for insert query'); // return immediately if no fields found return null; @@ -1269,7 +1269,7 @@ SQLConnector.prototype.buildFields = function(model, data, excludeIds) { */ SQLConnector.prototype.buildFieldsFromArray = function(model, data, excludeIds) { const fields = []; - if (data.length > 0) { + if (Array.isArray(data) && data.length > 0) { const keys = Object.keys(data[0]); for (let i = 0; i < data.length; i++) { fields.push(this._buildFieldsForKeys(model, data[i], keys, excludeIds));