Sequelize default method findOne bug

Viewed 45

Obs.: I am using Sequelize latest version, migrations, controller and models

I have this model called Tokens:

'use strict';
module.exports = (sequelize, DataTypes) => {
  const Tokens = sequelize.define('Tokens', {
    usuarios_id: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    token: {
      type: DataTypes.STRING,
      unique: true
    },
    empresa_id: {
      type: DataTypes.INTEGER,
      allowNull: false
    }
  }, {
    paranoid: false,
    freezeTableName: true
  });
  Tokens.associate = function(models) {
    // associations can be defined here
  };
  return Tokens;
};

I call the method findOne() in my middleware like this:

const token = await Tokens.findOne({ where: { token: tokenHeader }})

The logging returns more fields that i have, but i removed them from model and migration:

Executing (default): SELECT "id", "usuarios_id", "token", "empresa_id", "createdAt", "updatedAt" FROM "Tokens" AS "Tokens" WHERE "Tokens"."token" = '900150983cd24fb0d6963f7d28e17f72';

1 Answers

By default, Sequelize will add the attributes createdAt and updatedAt to your model so you will be able to know when the database entry went into the db and when it was updated last. If you do not want those fields, you can pass timestamps: false to configuration.

Link to the documentation: https://sequelize.org/v5/manual/models-definition.html#timestamps

Related