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

321
Visualizações
TypeORM: how to use In() with @ManyToMany relationship?

I have two entities: Something and Other (prototypes are below).

How can I use In() method to find all Somethings that have related Others by array of Others ids?

I need something like this:

const smths: Array<Something> = await connection.getRepository(Something).find({
    others: In(arrayWithOthersIds),
});

Entities:

@Entity()
class Something {
    @PrimaryGeneratedColumn('uuid')
    id: string;

    @ManyToMany(() => Other, (other) => other.smths, { cascade: true })
    others: Other[];
}

@Entity()
class Other {
    @PrimaryGeneratedColumn('uuid')
    id: string;

    @ManyToMany(() => Something, (smth) => smth.others, { cascade: true })
    smths: Something[];
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You must use @JoinTable() from 1 side of your many-to-many relationship. Also as I know you can not use { cascade: true } on both sides, so remove one. And use this query:

const smths: Something[] = await connection
   .getRepository(Something)
   .createQueryBuilder('smth')
   .innerJoin("smth.others", "others")
   .where('others.id IN (:...ids)', { ids } ) // ids = [1, 2..]
   .getMany();
about 4 years ago · Juan Pablo Isaza Relatório
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