Suppose I have this model:
module.exports = {
attributes: {
title: {
type: 'string',
required: true
},
content: {
type: 'string',
required: true
},
createdBy: {
type: 'string',
required: true
}
}
}
I need to set the current user id to the model's createdBy attribute. I thought I could do that with the beforeValidate lifecycle callback, but I can't access the request object where the current user is stored. Is there a way to access it, or should I solve this somehow else?
I tried this with no success:
beforeValidate: function (values, next) {
var req = this.req; // this is undefined
values.createdBy = req.user.id;
next();
}