Node.js SailsJS:无法在beforeCreate中创建模型

Node.js SailsJS:无法在beforeCreate中创建模型,node.js,sails.js,Node.js,Sails.js,我使用SailsJS(v0.12.3),我想在创建用户配置文件之前创建一个用户。我的问题是用户创建成功,但UserProfile没有成功 这是我的UserProfile型号: beforeCreate: function (userProfile, cb) { // Creating user login console.log("Creating user login: ", userProfile); User.create({ username: "

我使用SailsJS(v0.12.3),我想在创建用户配置文件之前创建一个用户。我的问题是用户创建成功,但UserProfile没有成功

这是我的
UserProfile
型号:

beforeCreate: function (userProfile, cb) {
    // Creating user login
    console.log("Creating user login: ", userProfile);
    User.create({
        username: "abc",
        password: "1234567890"
    }).then(function (user) {
        console.log("Creating user done: ", user)
        userProfile.appUser = user.id;
        userProfile.code = user.username;
        cb(null, userProfile);
    }).catch(function (err) {
        console.log("ABC", err);
        cb(err);
    });
}
控制台输出:

Creating user login:  { firstName: 'Vu',
  lastName: 'Bao',
  gender: 1,
  phoneNumber: '0987654321',
  id: '29b1b37b-ca95-4fd0-8cf8-e35a25af4616',
  code: '1469529082587',
  isVerified: false,
  totalVisit: 0 }
我可以看到消息
创建用户登录…
已打印,但我看不到日志消息
创建用户完成…
ABC
错误

结果:在数据库中,我创建了
user
,但
userProfile
没有

如何在正确创建UserProfile之前创建用户模型


谢谢大家!

过一会儿,阅读有关模型操作的内容。我发现我的代码没有回调我在
用户
模型中定义的
创建后
函数。因此,我确实在创建后删除了函数
,然后它就可以工作了

// ./api/models/User.js
afterCreate: function (user, cb) {
    // i commented a lots in this function, but did not callback cb
    // then i remove this method because I did not need it anymore
    // ...
}

谢谢你的阅读。希望这能帮助别人

确保在使用生命周期回调时将回调。