diff --git a/lib/adapter.js b/lib/adapter.js index 0267fa5..61f1262 100644 --- a/lib/adapter.js +++ b/lib/adapter.js @@ -257,6 +257,7 @@ const Adapter = { create (connectionName, tableName, record, cb) { let cxn = this.connections.get(connectionName) let pk = this.getPrimaryKey(cxn, tableName) + let newRecord; return cxn.knex.transaction(txn => { return txn.insert(Util.castRecord(record)) @@ -265,11 +266,13 @@ const Adapter = { return txn.select().from(tableName).where('rowid', rowid) }) .then(([ created ]) => { - let record = Util.castSqlValues(created, cxn.collections[tableName]) - _.isFunction(cb) && cb(null, record) - return record + newRecord = Util.castSqlValues(created, cxn.collections[tableName]) + return newRecord }) .catch(AdapterError.wrap(cb)) + }).then(() => { + _.isFunction(cb) && cb(null, newRecord) + return newRecord; }) },