Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

401
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda