sequelize-typescript
sequelize-typescript copied to clipboard
Define unique index on multiple columns in sequelize
Is this feature supported?
yes it is, just give the index the same name on the fields. https://www.npmjs.com/package/sequelize-typescript#index
eg.
@Table
export class UserObject extends Model{
@Index({
name:'UserIdObjectId',
unique:true,
})
@Column
public userId!: number;
@Index({
name:'UserIdObjectId',
unique:true,
})
@Column
public objectId!: number;
}
or specify the index on the table attribute
@Table({
indexes:[
{ fields: ['userId','objectId'], unique:true}
]
})
export class UserObject extends Model{
@Column
public userId!: number;
@Column
public objectId!: number;
}
could it be that the second method ({ fields: ['userId','objectId'], unique:true}) not only adds a composite index, but also 2 single indexes on the individual columns?
is this behavior intended or just not well documented ?