不会触发sailsjs beforeCreate [英] sailsjs beforeCreate is not triggered

查看:84
本文介绍了不会触发sailsjs beforeCreate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有基本模型的空白Sails 0.9.8应用程序:

I have a blank sails 0.9.8 app with a very basic model:

module.exports = {

  attributes: {

    nickname: 'string',
    encryptedPassword: 'string',

    beforeCreate: function(values, next){
        values.encryptedPassword = "123";
        next();
    }   
  }

};

当我从控制台创建新用户时,未调用beforeCreate方法,因此未创建任何已加密的密码.
我确定我在这里遗漏了一些东西,但找不到答案.有什么主意吗?

When I create a new User from the console, the beforeCreate method is not called, thus no encryptedPassword created.
I'm sure I'm missing a little something here but cannot find out what. Any idea ?

推荐答案

您必须将beforeCreate放置在属性之外.参见 https://github.com/balderdashy/sails-docs/blob/master /models.md#lifecycle-callbacks

You have to place beforeCreate outside of the attributes. See https://github.com/balderdashy/sails-docs/blob/master/models.md#lifecycle-callbacks

这篇关于不会触发sailsjs beforeCreate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆