diff --git a/lib/sql.js b/lib/sql.js index 4f07a6b..c8c3693 100644 --- a/lib/sql.js +++ b/lib/sql.js @@ -707,8 +707,16 @@ SQLConnector.prototype.createAll = function(model, data, options, callback) { if (err) { callback(err); } else { - const insertedId = self.getInsertedId(model, info); - callback(err, insertedId); + const insertedIds = self.getInsertedIds(model, info); + // We need to parse the ids created and map them back into the model + const returnData = []; + const idPropName = self.propertyName(model, self.idColumn(model)); + for (let i = 0; i < insertedIds.length; i++) { + const saved = Object.assign({}, data[i]); + saved[idPropName] = insertedIds[i]; + returnData.push(saved); + } + callback(err, returnData); } }); }; @@ -1798,6 +1806,16 @@ SQLConnector.prototype.getInsertedId = function(model, info) { throw new Error(g.f('{{getInsertedId()}} must be implemented by the connector')); }; +/** + * Parse the result for SQL INSERT (bulk) for newly inserted ids + * @param {String} model Model name + * @param {Object} info The status object from driver + * @returns {*} The inserted id values as an array + */ +SQLConnector.prototype.getInsertedIds = function(model, info) { + throw new Error(g.f('{{getInsertedIds()}} must be implemented by the connector')); +}; + /** * Execute a SQL statement with given parameters * @param {String} sql The SQL statement