Tengo dos entidades: Something y Other (los prototipos están abajo).
¿Cómo puedo usar el método In() para encontrar todos los Somethings que tienen Others relacionados por una matriz de ID de Others ?
Necesito algo como esto:
const smths: Array<Something> = await connection.getRepository(Something).find({ others: In(arrayWithOthersIds), });Entidades:
@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[]; }Debe usar @JoinTable() desde 1 lado de su relación de muchos a muchos. Además, como sé, no puede usar { cascade: true } en ambos lados, así que elimine uno. Y usa esta consulta:
const smths: Something[] = await connection .getRepository(Something) .createQueryBuilder('smth') .innerJoin("smth.others", "others") .where('others.id IN (:...ids)', { ids } ) // ids = [1, 2..] .getMany();