Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task done
callmeteus opened this issue Apr 20, 2024 · 2 comments · May be fixed by #1721
Open
1 task done

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

callmeteus opened this issue Apr 20, 2024 · 2 comments · May be fixed by #1721

Comments

@callmeteus
Copy link

callmeteus commented Apr 20, 2024

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;
}
callmeteus added a commit to callmeteus/sequelize-typescript that referenced this issue Apr 20, 2024
@callmeteus callmeteus linked a pull request Apr 20, 2024 that will close this issue
@callmeteus
Copy link
Author

callmeteus commented Apr 20, 2024

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 }
]

@callmeteus
Copy link
Author

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

@callmeteus callmeteus reopened this Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant