Skip to content

Inconsistency field and attribute with option underscored  #11037

Closed

Description

@jsDotx3

Problem

When you used Express with Sequelize and modified the underscored parameter to true, the field of the relationship is created with snake case (relation_id) but when I use express js, I must specify it as camel case (RelationId).

Solution

Have consistency between the field of the database and the request (If I declare relation_id, it must also be relation_id in the request and not RelationId)

Why should this be in Sequelize

Because it allows to have consistency in the attributes.

Usage example

Define sequelize on model.util and load all models.

const sequelize = new Sequelize(config.database_url, {
   define: {
      underscored: true,
      timestamps: true,
      paranoid: true,
      createdAt: 'created',
      updatedAt: 'updated',
      deletedAt: 'deleted'
    },
  },
);

Model: Client with hasMany User.

Relation Client

 Client.associate = (models) => {
        models.Client.hasMany(models.User);
    };

Relation User

  User.associate = (models) => {
    models.User.belongsTo(models.Client)
  }

Request Express (optimal case)

{
"username": "git",
"client_id": 1
}

Request Express (current case)

{
"username": "git",
"ClientId": 1
}

In database, I have client_id , not ClientId as field of table User.

Activity

  1. added
    type: feature
    on Jun 5, 2019
  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

type: feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions