From 4b76c3feecad6ec257b1293ce4cac03f17e5df32 Mon Sep 17 00:00:00 2001 From: Pavel Ivanoff Date: Sat, 16 Sep 2017 15:20:28 +0300 Subject: [PATCH] Related model creation hook Related model hooks contained only `prototype.__updateById__${relationName}` method. But also `prototype.__create__${relationName}` have to be added to handle routes like `POST /product/{id}/reviews`. --- lib/read-only.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/read-only.js b/lib/read-only.js index 15d6ea1..a20301c 100644 --- a/lib/read-only.js +++ b/lib/read-only.js @@ -106,6 +106,13 @@ module.exports = Model => { } return next() }) + + Model.beforeRemote(`prototype.__create__${relationName}`, (ctx, modelInstance, next) => { + if (typeof AffectedModel.stripReadOnlyProperties === 'function') { + return AffectedModel.stripReadOnlyProperties(modelName, ctx, modelInstance, next) + } + return next() + }) } })