fix(primaryKey): use model.primaryKey instead of hardcoded id for id routes, fixes #9

This commit is contained in:
Mahdi Dibaiee
2016-07-13 11:26:46 +04:30
parent 29ee49fc62
commit 6c46ff68d0
5 changed files with 26 additions and 17 deletions

View File

@ -54,7 +54,7 @@ export const get = (server, model) => {
const include = parseInclude(request);
const where = parseWhere(request);
const { id } = request.params;
if (id) where.id = id;
if (id) where[model.primaryKeyField] = id;
const instance = await model.findOne({ where, include });
@ -122,7 +122,7 @@ export const destroy = (server, model) => {
@error
async handler(request, reply) {
const where = parseWhere(request);
if (request.params.id) where.id = request.params.id;
if (request.params.id) where[model.primaryKeyField] = request.params.id;
const list = await model.findAll({ where });