title: TypeORM - Search and populate Many-to-Many relation
body: <p>I have two entities <code>Tag</code> and <code>Photo</code>:</p>
  <pre><code>// tag.entity.ts
  
  import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
  
  @Entity()
  export class Tag {
    @PrimaryGeneratedColumn()
    id!: number;
  
    // Other columns
  }
  </code></pre>
  <pre><code>// photo.entity.ts
  
  import { Entity, JoinTable, ManyToMany, PrimaryGeneratedColumn, } from 'typeorm';
  import { Tag } from './tag.entity';
  
  @Entity()
  export class Photo {
    @PrimaryGeneratedColumn()
    id!: number;
  
    @ManyToMany(type =&gt; Tag, { eager: true })
    @JoinTable()
    tags!: Tag[];
  
    // Other columns
  }
  </code></pre>
  <p>I need to filter results from <code>photos</code> table using results from <code>tags</code> table.</p>
  <pre><code>const photos = await photosRepository
    .createQueryBuilder('photo')
    .leftJoinAndSelect('photo.tags', 'tag')
    .where('tag.name LIKE :searchQuery', { searchQuery: 'nature%' })
    .skip(0)
    .take(10)
    .getMany();
  </code></pre>
  <p>The query above works fine: <code>photos</code> table records are filtered using <code>tag.name</code> column from <code>tags</code> table.</p>
  <p>The issue is that an each photo entity in returned <code>photos</code> array contains <strong>only</strong> filtered (<code>tag.name LIKE :searchQuery</code>) <code>tags</code> relation entities. What I need is to eager load <strong>all</strong> <code>tags</code> relation entities for each photo. Is it possible somehow?</p>
  <p>For example, with Laravel's Eloquent it's possible achive what I need with:</p>
  <pre><code>$photos = Photo::query()
    -&gt;with('tags')
    -&gt;whereHas('tags', function (Builder $query) {
      $query-&gt;where('tags.name', 'like', 'nature%');
    })
    -&gt;skip(0)
    -&gt;take(10)
    -&gt;get();
  </code></pre>