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

Unique property in model definition is not case-sensitive. #1696

Open
2 tasks
aryag-hashtechy opened this issue Oct 5, 2023 · 1 comment
Open
2 tasks

Unique property in model definition is not case-sensitive. #1696

aryag-hashtechy opened this issue Oct 5, 2023 · 1 comment

Comments

@aryag-hashtechy
Copy link

aryag-hashtechy commented Oct 5, 2023

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
Copy link

cth166 commented Oct 5, 2023

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

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

No branches or pull requests

2 participants