【问题标题】:Returned object's Id is ZERO ( creating a record in database )返回对象的 ID 为零(在数据库中创建记录)
【发布时间】:2014-03-26 21:10:36
【问题描述】:

当我尝试使用console.log(user); 打印出用户时,我发现 id 为零。但是,在数据库(mysql)中,用户 id 显示的是正确的值,即 uuid。

以下是我的用户模型

module.exports = {

  tableName : 'user',
  autoPK : false,
  attributes: {

  id: {
      type : 'string',
      unique : true,
      primaryKey : true,
      uuidv4 : true,
      columnName: 'id',
      defaultsTo : uuid.v4()
  },

  // { ..... other fields} 
}    

以下是我的创建函数:

 User.create(userObj).done(function(err, user){
  console.log(user);   
.... // other codes
 }

【问题讨论】:

  • 你运行的是什么版本的 Sails/sails-mysql?
  • 我正在使用 Sails v0.10.0-rc4 和sails-mysql 0.10.0-rc2。
  • 检查一下...与此同时,您需要defaultsTo: uuid.v4,而不是defaultsTo: uuid.v4()...除非您希望每个实例都使用相同的UUID!
  • 好的。感谢您指出这一点。

标签: javascript mysql node.js sails.js waterline


【解决方案1】:

啊,看来您在sails-mysql 的最新测试版中发现了一个错误。它现在是fixed and published,所以如果你删除你的node_modules/sails-mysql 文件夹和npm install sails-mysql@beta,你应该已经准备好了。谢谢!

【讨论】:

    猜你喜欢
    • 2019-03-05
    • 2010-10-09
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多