I am trying to do the following thing:
I have a model, say myModel which has some method calculateSomething. I defined that function by writing something like this in the MyModel.js file:
MyModel.prototype.calculateSomething = function(cb){
...
return cb(null,result)
}
Now I want to include the result of calculateSomething in the json whenever an instance of MyModel is returned from the api.
How do I do this? I tried using the "loaded" hook, but I believe this hook gets executed before the MyModel instance is created, so I can't call the calculateSomehing method there.
EDIT: It turns out that I can just use the "loaded" hook. I can use the ctx.instance in the hook to get the object.
I was confused by the documentation : "LoopBack invokes this hook after the connector fetches data, but before creating a model instance from that data". Is the documentation wrong or am I misunderstanding it?