【问题标题】:In sails.js, how to access session variables in method beforeCreate of model?在sails.js中,如何在模型的beforeCreate方法中访问会话变量?
【发布时间】:2015-01-26 19:15:48
【问题描述】:

这是我现在在创建用户实体之前的用户模型,我想将值会话变量自动赋予 createdBy 和 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;
          },
        }

【问题讨论】:

    标签: mysql node.js sails.js waterline


    【解决方案1】:

    我也在寻找同样的东西。找到了一些相关资源,这些资源可能有助于为您指明正确的方向。不幸的是,没有很好的支持让帆在模型上自动设置 UpdatedBy 和 CreatedBy 属性。

    【讨论】:

      猜你喜欢
      • 2014-01-26
      • 1970-01-01
      • 1970-01-01
      • 2019-01-01
      • 2015-06-29
      • 2017-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多