sequelize/sequelize-typescript

Unique property in model definition is not case-sensitive.

aryag-hashtechy opened this issue · 1 comments

Issue

Versions

  • sequelize:
  • sequelize-typescript:
  • typescript:

Issue type

  • bug report
  • feature request

Actual behavior

I have a model defined as follows:-

import {
  Model,
  Column,
  Table,
  DataType,
  PrimaryKey,
  AutoIncrement,
  BelongsToMany,
  ForeignKey
} from 'sequelize-typescript'
import { Activity } from './activity.entity'
import { HashtagMaster } from './hashtagmater.entity'

@Table({ tableName: 'hashtags' })
export class Hashtag extends Model<Hashtag> {
  @PrimaryKey
  @AutoIncrement
  @Column({
    type: DataType.INTEGER,
    allowNull: false,
    unique: true
  })
  id: number

  @Column({
    type: DataType.STRING,
    unique: true,
    allowNull: false
  })
  name!: string

  @Column({
    type: DataType.INTEGER,
    allowNull: false,
    defaultValue: 0
  })
  count!: number

  @BelongsToMany(() => Activity, () => HashtagMaster)
  activities!: Activity[]
}

Notice the unique property assigned to column name. I have a record in which the name is #test. However, when I attempt to create a new record with name as #Test, sequelize throws a duplicate entry error. Not sure if others are facing the same issue.

Expected behavior

It should accept #test and #Test both, as both are unique given that unique property implies case-sensitivity.

Steps to reproduce

Explained in the actual behaviour section.

cth166 commented

I tried a simple User Model which username is unique. And I add two records {username:'#test'} and {username:'#Test'}. It works fine. Then I add {username:'#test'} again. It throw an error. It is case-sensitivity.Maybe your problem is not related to name .
How about comment out this , just use the default behavior in sequelize-typescript?

@PrimaryKey
@autoincrement
@column({
type: DataType.INTEGER,
allowNull: false,
unique: true
})
id: number