Reputation: 775
This is my user model now before create user entity I want to auto give value session variable to createdBy and updatedBY.
module.exports = {
autoPK: false,
attributes: {
id:{columnName:'ID', type: 'integer', autoIncrement: true, primaryKey: true},
employeeId:{columnName:'EMPLOYEE_ID', type: 'string',unique : true},
firstName:{columnName:'FIRST_NAME', type: 'string'},
lastName:{columnName:'LAST_NAME', type: 'string'},
createdBy:{columnName:'CREATED_BY', model: 'user'},
updatedBy:{columnName:'CREATED_BY', model: 'user'},
},
beforeCreate: function(values, cb) {
values.createdBy=req.session.userId;
values.updatedBy=req.session.userId;
return values;
},
beforeUpdate: function(values, cb) {
values.updatedBy=req.session.userId;
return values;
},
}
Upvotes: 2
Views: 1406
Reputation: 20419
I was looking for the same thing. Found some relevant resources that may help point you in the right direction. Unfortunately, there isn't great support to have sails automatically set UpdatedBy and CreatedBy properties on models.
Upvotes: 1