user938363
user938363

Reputation: 10358

sequelize: createdAt empty in findOne()

I am using sequelize 5.6.1 to retrieve record from verifLog model on Nodejs 10.15 server:

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

But the createdAt is empty in hit even though there is a valid value (2019-04-27 23:10:15.827-07) in the table for createdAt:

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: {},
.......

Here is the VerifLog model:

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'],
        },
    ],
}); 

I have no clue why (only) createdAt is returned empty.

Upvotes: 1

Views: 247

Answers (1)

Harris Lummis
Harris Lummis

Reputation: 482

Try defining createdAt and updatedAt in your model. My guess is that though the data is available in the record, because you haven't defined the fields in your model attributes sequelize does not define getters for createdAt and updatedAt.

Upvotes: 1

Related Questions