Created
January 11, 2024 09:29
-
-
Save umutyerebakmaz/d49442f0aa70a43878131972fc764944 to your computer and use it in GitHub Desktop.
TypeORM @manytomany, establish a two-sided `CASCADE` structure for the ManyToMany relationship.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// You can set up the structure without creating this entity, but when the project grows, | |
// you will need the entity for leftJoin. | |
import { BaseEntity, Entity, PrimaryColumn } from 'typeorm'; | |
@Entity() | |
export class RequestUser extends BaseEntity { | |
@PrimaryColumn('uuid') | |
requestId: string; | |
@PrimaryColumn('uuid') | |
userId: string; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ManyToMany(() => User, user => user.requests, { onDelete: 'CASCADE' }) | |
@JoinTable({ name: 'request_user' }) | |
@Field(() => [User], { nullable: true }) | |
users: Promise<User[]>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ManyToMany(() => Request, request => request.users, { onDelete: 'CASCADE' }) | |
@Field(() => [Request], { nullable: true }) | |
requests: Promise<Request[]>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment