Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NDD-225]: 질문 객체, 리포지토리 구현 (1h / 2h) #70

Merged
merged 2 commits into from
Nov 20, 2023

Conversation

JangAJang
Copy link
Collaborator

@JangAJang JangAJang commented Nov 19, 2023

NDD-225 Powered by Pull Request Badge

Why

객체를 구현하는 과정에서, 기존의 댓글/대댓글과 카테고리에서 제가 이전에 했던 방식이 생각났습니다

  • 하위 카테고리가 존재
  • 상위 카테고리가 삭제되면 하위 카테고리는 자동 삭제
  • 하위 카테고리를 조회하면 상위 카테고리를 fetch해서 조회

현재 질문의 방식이 위와 비슷하다고 느꼈습니다.

  • origin 질문 존재
  • copy해서 질문 생성 가능
  • origin이 삭제되면 copy도 삭제
  • copy질문을 조회하면 상위 질문도 같이 조회(다른 사람이 복사된 질문을 복사할 때 copy가 아닌 origin을 복사

How

@Entity({ name: 'Question' })
export class Question extends DefaultEntity {
  @Column({ type: 'text' })
  readonly content: string;

  @ManyToOne(() => Category, { onDelete: 'CASCADE', eager: true })
  @JoinColumn({ name: 'category' })
  readonly category: Category;

  @ManyToOne(() => Question, { nullable: true, onDelete: 'CASCADE' })
  @JoinColumn({ name: 'origin' })
  readonly origin: Question;
}

이런 방식으로 객체를 만들어, 하위 질문이 상위 질문을 다대일로 가지게 만들었습니다.

Result

단일 테이블로 질문에 관련된 모든 쿼리 수행 가능 및 origin 삭제시 copy가 자동삭제

Prize

  • 기존 erd에서는 질문을 서로 다른 테이블에 저장하는 문제가 있었음
  • 해당 문제 해결 및 질문의 origin 바로 확인 가능

Copy link

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7cbc7e1
Status: ✅  Deploy successful!
Preview URL: https://bfe17162.gomterview.pages.dev
Branch Preview URL: https://feature-ndd-225.gomterview.pages.dev

View logs

@JangAJang JangAJang self-assigned this Nov 19, 2023
@JangAJang JangAJang added BE 백엔드 코드 변경사항 feature 새로운 기능이 추가 된 경우 labels Nov 19, 2023
Copy link
Collaborator

@quiet-honey quiet-honey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!!

@JangAJang JangAJang merged commit af8ba9b into dev Nov 20, 2023
1 check passed
@delete-merged-branch delete-merged-branch bot deleted the feature/NDD-225 branch November 20, 2023 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE 백엔드 코드 변경사항 feature 새로운 기능이 추가 된 경우
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants