With my Loopback project I have a model (ModelA) which references a property of type ModelB. For example (from common/models/modela.json):
"relations": {
"modelbs": {
"type": "hasMany",
"model": "ModelB",
"foreignKey": "ownerId"
}
}
I would like to use ModelB.afterRemote (from modelb.js) to filter some properties in response to GET /api/modelas/1/modelbs
. However, ModelB.afterRemote is never called. Instead, ModelA.afterRemote (from modela.js) is called with ModelB objects in ctx.result.
How do I implement an afterRemote for ModelBs without injecting the code into each top-level class that might happen to have relationships with ModelBs?
For reference, my call signature for afterRemote is,
ModelB.afterRemote('**', function (ctx, unused, next) { ... }