Ben Beri
Ben Beri

Reputation: 1201

TypeORM create constraint based on enum column and FK column?

I have the following table:

enter image description here

I must set a rule in that entity, so you can't have the same home_account_user_id and same account_status twice for example:

id | home_account_user_id | account_status
0  | 1                    | AWAY
0  | 1                    | AWAY

Should be:

id | home_account_user_id | account_status
0  | 1                    | AWAY
0  | 1                    | CLOSED

Is there a way to define it this way?

Upvotes: 1

Views: 468

Answers (1)

Lukasz Szozda
Lukasz Szozda

Reputation: 175924

You could use UNIQUE constraint/index:

CREATE UNIQUE INDEX udx_name ON tab_name(home_account_user_id, account_status);

Upvotes: 1

Related Questions