sequelize-typescript icon indicating copy to clipboard operation
sequelize-typescript copied to clipboard

Relation problem (source key and target key)

Open dhevanthareza opened this issue 4 years ago • 3 comments

Issue

Can i define source key and target key manually? i cant use @Primary for parent Model because the parent model have more than 1 key

Versions

^1.1.0

  • sequelize: ^5.21.5
  • sequelize-typescript: ^1.1.0
  • typescript: ^3.8.3

Issue type

  • [ ] bug report
  • [x ] feature request

dhevanthareza avatar Aug 11 '21 07:08 dhevanthareza

YES! I would Like to second this issue!!!! You might change the title:

Allow @ForeignKey annotation to specify any unique column.

@ForeignKey annotation always targets the primary key. Need to be able to specify an alternate. Constraint will look like: FOREIGN KEY (changable_localfield_FK) REFERENCES distantTable (FIXED_primaryKey) ON DELETE SET NULL ON UPDATE CASCADE,

While we can change what field is used in the local table to hold the foreign key, we can't seem to specify anything other than the primary key on the "Linked" table.

Quite a few legit scenarios where you may have more than one unique key in the table. e.g. you want to use autoincrement (forces use of Primary key), but you also need to capture a GUID, to ensure unique values across tables.

redevill avatar Aug 11 '21 21:08 redevill

I also have this need to customize the foreignkey other than using the primary key

Neil-UWA avatar Apr 15 '22 02:04 Neil-UWA