Skip to content

can't use @Index decorator with indexes at the model options #1720

Open

Description

@callmeteus

Issue

sequelize-typescript overrides the declarated model option indexes with the decorated indexes.
This is due to a misbehaviour in

Versions

  • sequelize-typescript: 2.1.6

Issue type

  • bug report

Related code

@Table({
    indexes: [
        {
            unique: true,
            fields: ["email"],
            name: "another_unique_email"
        }
    ]
})
export class Admin extends Model {
    /**
     * User email address.
     */
    @AllowNull(false)
    @Unique({
        name: "unique_email"
    })
    declare public email: string;
}

Activity

  1. added a commit that references this issue on Apr 20, 2024
  2. callmeteus commented on Apr 20, 2024

    @callmeteus
    Author

    I've submitted a PR that seems to fix the initial issue, but I've found another issue.
    indexArray isn't including @unique indexes.

    @Table({
        indexes: [
            {
                unique: true,
                fields: ["name", "email"],
                name: "example_composite_unique_index"
            }
        ]
    })
    export class Admin extends Model {
         /**
         * User full name.
         */
        @Unique("unique_admin_name")
        @Column(DataType.STRING(256))
        declare public name: string;
    
        /**
         * User email address.
         */
        @AllowNull(false)
        @Index("admin_email")
        declare public email: string;
    }

    This results in the following indexesArray:

    [
      { name: 'admin_email', fields: [ [Object] ], type: '', parser: null }
    ]
  3. callmeteus commented on Apr 27, 2024

    @callmeteus
    Author

    Wow, this is actually not closed, I've fixed it internally and just linked this issue internally for us to know about it.

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

Metadata

Metadata

Assignees

No one assigned

    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