续集:在findOne()中的createdAt为空

时间:2019-04-30 21:11:35

标签: node.js sequelize.js

我正在使用sequelize 5.6.1从Nodejs 10.15服务器上的verifLog模型中检索记录:

hit = await VerifLog.findOne({where : {vcode: vcode_received, 
                                        cell: cell, 
                                        cell_country_code: cell_country_code, 
                                        device_id: device_id, 
                                        redeemed: false}});

但是createdAthit中为空,即使表中有createdAt的有效值(2019-04-27 23:10:15.827-07):

hit is :  veriflog {
  dataValues:
   { id: 31,
     cell: '6303623200',
     cell_country_code: '1',
     vcode: '90282',
     device_id: '8c9c25711c7d0262',
     redeemed: false,
     user_id: '20',
     createdAt: 2019-04-28T06:10:15.827Z },
  _previousDataValues:
   { id: 31,
     cell: '6303623200',
     cell_country_code: '1',
     vcode: '90282',
     device_id: '8c9c25711c7d0262',
     redeemed: false,
     user_id: '20',
     createdAt: 2019-04-28T06:10:15.827Z },
  _changed: {},
.......

这是VerifLog模型:

const VerifLog = db.define('veriflog', {
    /* id: {type: Sql.INTEGER,
         primaryKey:true,
         autoIncrement: true,
         min: 1}, */
    cell: Sql.STRING,
    cell_country_code: Sql.STRING,
    vcode: Sql.STRING,
    device_id: Sql.STRING,
    redeemed: {
        type: Sql.BOOLEAN,
        default: false
    },
    user_id: Sql.INTEGER,
}, {
    timestamps: true,
    updatedAt: false,
    indexes: [
        {
            fields: ['cell_country_code', 'cell'],
        },
        {
            fields: ["device_id"],
        },
        {
            fields: ["redeemed"],
        },
        {
            fields: ['user_id'],
        },
    ],
}); 

我不知道为什么createdAt仅返回空。

1 个答案:

答案 0 :(得分:1)

尝试在模型中定义createdAtupdatedAt。我的猜测是,尽管记录中有可用数据,但是由于您尚未在模型属性中定义字段,因此sequelize不会为createdAtupdatedAt定义吸气剂。