I am writing an 'after save' hook and have some problem to read data.
What I would like to do is to access data in another model, but when doing this it is undefined.
Here is some code:
module.exports = function(Fault) {
Fault.observe('after save', function(ctx, next) {
ctx.Model.app.models.faulttype.find({where:{id:ctx.instance.faulttypeId}}, function(err, faulttype) {
if (err)
console.log(err);
console.log(faulttype);
console.log(faulttype.slogan);
....
}
I am using the ctx.Model.app.models to grab one of the other models I have (faulttype). The problem is then later when I use it.
In the first console.log it is writing all attributes and values for the faulttype, but when I try to use a specific attribute, as in the second console.log where I usefaulttype.
slogan I get the response that it is undefined. I don't understand why.
Any ideas/comments?