fix(primaryKey): use model.primaryKey
instead of hardcoded id
for id
routes, fixes #9
This commit is contained in:
@ -26,7 +26,7 @@ export const get = (server, a, b, names) => {
|
||||
|
||||
const base = await a.findOne({
|
||||
where: {
|
||||
id: request.params.aid,
|
||||
[a.primaryKeyField]: request.params.aid,
|
||||
},
|
||||
});
|
||||
const method = getMethod(base, names.b, false);
|
||||
@ -53,7 +53,7 @@ export const create = (server, a, b, names) => {
|
||||
async handler(request, reply) {
|
||||
const base = await a.findOne({
|
||||
where: {
|
||||
id: request.params.id,
|
||||
[a.primaryKeyField]: request.params.id,
|
||||
},
|
||||
});
|
||||
|
||||
@ -79,10 +79,12 @@ export const destroy = (server, a, b, names) => {
|
||||
|
||||
const base = await a.findOne({
|
||||
where: {
|
||||
id: request.params.aid,
|
||||
[a.primaryKeyField]: request.params.aid,
|
||||
},
|
||||
});
|
||||
|
||||
where[b.primaryKeyField] = request.params.bid;
|
||||
|
||||
const method = getMethod(base, names.b, false, 'get');
|
||||
const instance = await method({ where, include });
|
||||
await instance.destroy();
|
||||
@ -110,6 +112,8 @@ export const update = (server, a, b, names) => {
|
||||
},
|
||||
});
|
||||
|
||||
where[b.primaryKeyField] = request.params.bid;
|
||||
|
||||
const method = getMethod(base, names.b, false);
|
||||
|
||||
const instance = await method({ where, include });
|
||||
|
Reference in New Issue
Block a user