Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

400
Visualizações
Union type in typeorm relation for nested comments

I am trying to create kind of CRUD-blog with posts, users and comments. And would like to have 2-level comments like ones on Youtube: top-level comments are attached to video/post and replies are attached to top-level comments. So top-level comments have post as their parent and replies have top-level comment as their parent.

Does it meant that I have to use different entity classes(and thus different tables) for top-level comments and replies? Can typeorm handle union type as parent?

@Entity()
export class Comment extends CreatableEntity {

  @Column({ type: 'text' })
  content: string

  @ManyToOne(type => User, user => user.comments, {
    nullable: false,
  })
  author: User

  @ManyToOne(type => Post | Comment, parent => parentcomments, {
    nullable: false,
  })
  parent: Post | Comment

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda