Skip to content

Commit

Permalink
fix(blueprint): primary key not always called ID
Browse files Browse the repository at this point in the history
* Fix

* Update blueprint for update

Primary key not always called 'ID', we should check pk name

* Update update.js

* Update update.js
  • Loading branch information
canabina authored and ghaiklor committed Dec 10, 2016
1 parent 2f35c35 commit 836757c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions generators/blueprint/templates/api/blueprints/update.js
Expand Up @@ -13,9 +13,12 @@ module.exports = (req, res) => {
const Model = actionUtil.parseModel(req);
const pk = actionUtil.requirePk(req);
const values = actionUtil.parseValues(req);

const pkName = Model.primaryKey;
const criteria = {};
criteria[pkName] = pk;

Model
.update(pk, _.omit(values, 'id'))
.update(criteria, _.omit(values, pkName))
.then(records => records[0] ? res.ok(records[0]) : res.notFound())
.catch(res.negotiate);
};

0 comments on commit 836757c

Please sign in to comment.