From 2f4f5f4eed0a66b17492b529442592065b191209 Mon Sep 17 00:00:00 2001 From: Andrew Smiley Date: Tue, 2 Aug 2016 11:39:08 -0700 Subject: [PATCH] Added option to grab created resource id from original object instead of the return object. --- src/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index bfeece5..74aac7f 100644 --- a/src/index.js +++ b/src/index.js @@ -37,6 +37,7 @@ class Service { this.id = options.id || 'id'; this.paginate = options.paginate || {}; this.table = options.name; + this.idFromData = options.idFromData; } // NOTE (EK): We need this method so that we return a new query @@ -160,8 +161,10 @@ class Service { } _create(data, params) { - return this.db().insert(data, this.id).then(rows => this._get(rows[0], params)) - .catch(errorHandler); + return this.db().insert(data, this.id).then(rows => { + const id = this.idFromData ? data[this.id] : rows[0]; + return this._get(id, params); + }).catch(errorHandler); } create(data, params) {