Sequelize-typescript: Composite unique constraint ?

Created on 19 Oct 2017  路  1Comment  路  Source: RobinBuschmann/sequelize-typescript

How can set composite unique constraint ?
e.g. I have class

@Table
class SomeTable {
   ...
   id: number;

   ...
   otherId: number;

   ...
   something: string;
}

and I want to have unique(otherId, something).

Most helpful comment

Hey @tomislavhren , you can achieve this like so:

const SOME_UNIQUE_KEY = 'test';

@Table
class SomeTable {

   @Column({unique: SOME_UNIQUE_KEY})
   otherId: number;

   @Column({unique: SOME_UNIQUE_KEY})
   something: string;
}

>All comments

Hey @tomislavhren , you can achieve this like so:

const SOME_UNIQUE_KEY = 'test';

@Table
class SomeTable {

   @Column({unique: SOME_UNIQUE_KEY})
   otherId: number;

   @Column({unique: SOME_UNIQUE_KEY})
   something: string;
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

YaroslavOsetrov picture YaroslavOsetrov  路  3Comments

oscarcalvo picture oscarcalvo  路  3Comments

libvirtadept picture libvirtadept  路  4Comments

josecolella picture josecolella  路  4Comments

lilling picture lilling  路  4Comments