Skip to content

Commit

Permalink
Merge pull request #112 from modern-agile-team/feature/comment
Browse files Browse the repository at this point in the history
Refactor(2swo/Server) 엔티티 onDelete설정
  • Loading branch information
2swo authored Nov 10, 2023
2 parents 6a5ca89 + 2e19e08 commit 571fe2d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 24 deletions.
4 changes: 3 additions & 1 deletion src/boards/entities/board-image.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export class BoardImage {
@PrimaryGeneratedColumn()
id: number;

@ManyToOne(() => Board, (board) => board.boardImages)
@ManyToOne(() => Board, (board) => board.boardImages, {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'board_id' })
board: Board;

Expand Down
16 changes: 6 additions & 10 deletions src/boards/entities/board.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,22 @@ export class Board {
@Column({ name: 'user_id' })
userId: number;

@ManyToOne(() => User, (user) => user.board)
@ManyToOne(() => User, (user) => user.board, {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'user_id' })
user: User;

@OneToMany(() => BoardImage, (boardImages) => boardImages.board, {
onDelete: 'CASCADE',
})

@OneToMany(() => BoardImage, (boardImage) => boardImage.board)
boardImages: BoardImage[];

@OneToMany(() => BoardLike, (boardLike) => boardLike.boardId, {
onDelete: 'CASCADE',
})
@OneToMany(() => BoardLike, (boardLike) => boardLike.boardId)
boardLike: BoardLike;

@OneToMany(
() => BoardNotification,
(BoardNotification) => BoardNotification.board,
{
onDelete: 'CASCADE',
},
)
boardNotification: BoardNotification;

Expand Down
12 changes: 9 additions & 3 deletions src/comments/entities/comment-like.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ export class CommentLike {
@PrimaryGeneratedColumn()
id: string;

@ManyToOne(() => User)
@ManyToOne(() => User, {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'user_id' })
userId: User;

@ManyToOne(() => Comment)
@ManyToOne(() => Comment, {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'comment_id' })
commentId: Comment;

@ManyToOne(() => ReComment)
@ManyToOne(() => ReComment, {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'recomment_id' })
recommentId: ReComment;
}
12 changes: 7 additions & 5 deletions src/comments/entities/comment.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ export class Comment {
@PrimaryGeneratedColumn()
id: number;

@ManyToOne(() => User)
@ManyToOne(() => User, {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'user_id' })
user: User;

@Column({ name: 'user_id' })
userId: number;

@OneToMany(() => ReComment, (reComment) => reComment.comment, {
onDelete: 'CASCADE',
})
@OneToMany(() => ReComment, (reComment) => reComment.comment)
reComment: ReComment[];

@ManyToOne(() => Board)
@ManyToOne(() => Board, {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'board_id' })
board: Board;

Expand Down
8 changes: 6 additions & 2 deletions src/comments/entities/recomment.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ export class ReComment {
@PrimaryGeneratedColumn()
id: number;

@ManyToOne(() => User)
@ManyToOne(() => User, {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'user_id' })
user: User;

@Column({ name: 'user_id' })
userId: number;

@ManyToOne(() => Comment, (comment) => comment.reComment)
@ManyToOne(() => Comment, (comment) => comment.reComment, {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'comment_id' })
comment: Comment;

Expand Down
10 changes: 7 additions & 3 deletions src/common/notice/entities/board-notice.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@ export class BoardNotification {
@Column({ name: 'board_id' })
boardId: number;

@ManyToOne(() => Board, (board) => board.boardNotification)
@ManyToOne(() => Board, (board) => board.boardNotification, {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'board_id' })
board: Board;

@Column({ name: 'sender_id' })
senderId: number;

@ManyToOne(() => User)
@ManyToOne(() => User, {
onDelete: 'CASCADE',
})
@JoinColumn({ name: 'sender_id' })
sender: User;

@Column({ name: 'receiver_id' })
receiverId: number;

@ManyToOne(() => User)
@ManyToOne(() => User, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'receiver_id' })
receiver: User;

Expand Down

0 comments on commit 571fe2d

Please sign in to comment.