Skip to content

Some attributes seems to be accepted in camcelCase only ( {underscore: true} not respected?) #11149

Closed

Description

@younanjo

What are you doing?

give the following Model called Demo:

export default function(sequelize, DataTypes) {
  const Demo = sequelize.define(
    'Demo',
    {
      id: {
        allowNull: false,
        primaryKey: true,
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
      },
      message: {
        type: DataTypes.STRING,
        allowNull: false,
      },
      created_at: {
        type: DataTypes.DATE,
        defaultValue: DataTypes.NOW,
        allowNull: false,
      },
      updated_at: {
        type: DataTypes.DATE,
        defaultValue: DataTypes.NOW,
        allowNull: false,
      },
      deleted_at: {
        type: DataTypes.DATE,
        defaultValue: null,
        allowNull: true,
      },
    },
    {

      freezeTableName: true,
      tableName: 'Demo',
      name: {
        singular: 'Demo',
        plural: 'Demos',
      },
      timestamps: true,
      underscored: true,
      paranoid: true,
      deletedAt: 'deleted_at',
    }
  );

  return Demo;
}

When I'm trying to insert a new Record using:

const yesterday = moment().subtract(1, 'day').toDate();
const demo = await Demo.create(
    {
      message: 'created_at seems to be incorrect',
      created_at: yesterday,
      updated_at: yesterday,
    },
  );

The result is:

{
    "id": "7f406762-f61c-4a59-ae6f-7112c72f4eea",
    "message": "created_at seems to be incorrect",
    "created_at": "2019-07-04T05:02:06.604Z",
    "updated_at": "2019-07-04T05:02:06.604Z",
    "createdAt": "2019-07-04T05:02:06.604Z"
    "updatedAt": "2019-07-04T05:02:06.604Z",
    "deleted_at": null,
}

I would expect the created_at to be 2019-07-03T05:02:06.602Z, however it gets set as 2019-07-04T05:02:06.726Z which is default (now).

if i pass the date as createdAt it works as expected!

const demo = await Demo.create(
    {
      message: 'created_at seems to be incorrect',
      createdAt: yesterday,
      updated_at: yesterday,
    },
  );

// response
{
    "id": "249d2682-e9b0-4a63-854a-2712e583c796",
    "message": "created_at seems to be incorrect",
    "created_at": "2019-07-03T05:02:06.602Z",
    "createdAt": "2019-07-03T05:02:06.602Z",
    "updated_at": "2019-07-04T05:02:06.726Z",
    "updatedAt": "2019-07-04T05:02:06.726Z",
    "deleted_at": null,
  }

This is only happening in v5 (v5.9.2). v4 is good. Trying to upgrade because of security warnings. Anyone else seeing this?

Environment

Dialect:

  • mysql
  • postgres
  • sqlite
  • mssql
  • any
    Dialect library version: pg
    Database version: 9.6
    Sequelize version: v5.9.2
    Node Version: 8.16.0
    OS: Ubuntu

If TypeScript related: TypeScript version: XXX
Tested with latest release:

  • No
  • Yes, specify that version: v5.9.2

Activity

  1. ahas commented on Jul 5, 2019

    @ahas

    I have a same problem.
    Sequelize v5 no more supports underscoredAll option so have camelCased attributes.
    underscored option is only applied for table fields not attributes. This feature makes me angry.

  2. self-assigned this
    on Jul 23, 2019
  3. papb commented on Jul 25, 2019

    @papb
    Member

    Closing in favor of #11225.

    When #11225 gets closed, if anyone thinks this particular issue is still an issue, please ping me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions