can't use @Index decorator with indexes at the model options
Opened this issue · 2 comments
callmeteus commented
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 commented
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 commented
Wow, this is actually not closed, I've fixed it internally and just linked this issue internally for us to know about it.