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

setting custom name for foreign key constraint #1707

Open
1 task
dev-mat opened this issue Jan 31, 2024 · 1 comment
Open
1 task

setting custom name for foreign key constraint #1707

dev-mat opened this issue Jan 31, 2024 · 1 comment

Comments

@dev-mat
Copy link

dev-mat commented Jan 31, 2024

Issue

Cannot set custom foreign key constraint name

Versions

2.1.5

  • sequelize: 6.32.0
  • sequelize-typescript: 2.1.5
  • typescript: 4.7.4

Issue type

  • bug report
  • [ x] feature request

Actual behavior

Cannot set custom foreign key constraint name using decorators. Actually I am setting { constraints: false } in @BelongsTo decorator and adding foreign keys with specified names using queryInterface.

Expected behavior

I there an option to specify foreign key constraint name using decorators? If not, do you plan to add this feature ?

Steps to reproduce

Related code

  /* Table A */
  @HasMany(() => B)
  bs: B[]
  
  /* Table B */
  @ForeignKey(() => A)
  @Column({ allowNull: false })
  aId: number

  // I want to specify key name, for eg. 'FK_my_custom_named_key'
  @BelongsTo(() => A, { foreignKey: 'aId', constraints: false })
  a: A
  
@SteeleParker
Copy link

SteeleParker commented Feb 18, 2024

According to inline documentation and the compiler itself the following syntax is acceptable, however it is my experience that this has no effect and this value is ignored.

    @BelongsTo(() => SomeOtherModel, {
        foreignKey: {
            field: 'someOtherModelId',
            name: 'ThisModel_SomeOtherModelId_foreign_idx'
        }
    })
    someOtherModel?: SomeOtherModel;

    @ForeignKey(() => SomeOtherModel)
    @Column({
        type: DataType.UUID,
        allowNull: false,
    })
    someOtherModelId!: string;

I am unsure if this is due to my local configuration due to its complexity so I have not yet raised this as a bug.

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