title: How to filter one-to-many relations with query builder
body: <p>I have </p>
  
  <pre><code>@Entity('procedures')
  export class ProcedureEntity {
  
      @PrimaryGeneratedColumn()
      id: number;
  
      @OneToMany(type =&gt; MediaFileEntity, media =&gt; media.procedure, {
          cascade: true
      })
      files: MediaFileEntity[];
  
  };
  </code></pre>
  
  <p>and </p>
  
  <pre><code>@Entity('media_files')
  export class MediaFileEntity {
  
      @PrimaryGeneratedColumn()
      id: number;
  
      @Column({ nullable: true })
      deletedAt: Date;
  
      @ManyToOne(type =&gt; ProcedureEntity, procedure =&gt; procedure.files)
      procedure: ProcedureEntity;
  
  };
  </code></pre>
  
  <p>Does anybody know how do I create a query builder so that I get all the procedures, but with media files that have <code>deletedAt</code> NULL ?</p>
  
  <p>I'm trying to do </p>
  
  <pre><code>const procedures = await this.procedureRepository
      .createQueryBuilder("procedure")
      .leftJoinAndSelect("procedure.doctor", "doctor")
      .leftJoinAndSelect("procedure.patient", "patient")
      .innerJoin('procedure.files', 'mediaFile', 'mediaFile.deletedAt IS NULL')
      .where("(patient.id = :id OR doctor.id = :doctorId)", { id: user.id, doctorId: user.id })
      .andWhere('procedure.deletedAt IS NULL')
      .getMany();
  </code></pre>
  
  <p>but I get <code>Cannot find name 'where'</code>. Which is odd, because <code>this.procedureRepository
      .createQueryBuilder("procedure")</code> is also a <code>SelectQueryBuilder&lt;ProcedureEntity&gt;</code> and so is <code>this.procedureRepository
      .createQueryBuilder("procedure")
      .leftJoinAndSelect("procedure.doctor", "doctor")
      .leftJoinAndSelect("procedure.patient", "patient")
      .innerJoin('procedure.files', 'mediaFile', 'mediaFile.deletedAt IS NULL');</code></p>
  
  <p>Thanks in advance!</p>
  
  <p>EDIT: Funny enough, I already had the answer. But I'm gonna leave it here anyway, for posterity </p>