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

129
Visualizações
TypeORM how to untie an entity from an entity

I have an entity Article, and I would like to unbind all Tag [] from the entity when updating, how can I unbind all tags from the record without removing the tags

Article Entity:

@Entity()
export class Article implements Likeable, Viewable {
  @PrimaryColumn()
  id: string;

  @Column()
  title: string;

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

  @Column('uuid')
  authorId: string;

  @Column('uuid', { nullable: true })
  coverImageId?: string;

  @Column('uuid', { nullable: true })
  imageId?: string;

  @Column('uuid', { nullable: true })
  artId?: string;

  @ManyToMany(() => Tag, { eager: true })
  @JoinTable()
  tags: Tag[];

  @Column()
  createdAt: Date;
}

Tag entity:

@Entity()
export class Tag {
  @PrimaryColumn()
  id: string;
  @Column()
  name: string;
}

update method

async update(articleId: string, body: UpdateArticle, userId: string): Promise<void> {
    const article = await this.articleRepository.findOne(articleId);
    .....
    let tags: Tag[];
    if (body.tags) {
      // unlink all tags from the post
      await this.tagService.saveNonExistent(body.tags);
      tags = await this.tagRepository.findAllByNames(body.tags);
    }
......
    await this.articleRepository.save(article);
  }

Is there any method for cleaning up collections?

Thanks in advance for your answer!

about 4 years ago · Juan Pablo Isaza
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