title: Problem ordering nested entities in TypeORM
body: <p>I've got a self-referencing entity called <code>Category</code>. Basically, it's just a folder that may contain subfolders, but the subfolders cannot contain any other folders. Simple as that. It's possible for the user to move these folders around this way changing their positions relative to each other. On the <code>Category</code> entity I've got a prop called <code>position</code> and when I return all the categories for a specific user I need to order them by position. That's to say the query should look something like this:</p>
  <pre><code>const categories = await this.categoryRepository.createQueryBuilder('category')
    .where('category.user.id = :userId', { userId })
    .leftJoinAndSelect('category.entries', 'catEntries')
    .leftJoinAndSelect('catEntries.images', 'catImages')
    .leftJoinAndSelect('category.subcategories', 'subs')
    .leftJoinAndSelect('subs.entries', 'subCatEntries')
    .leftJoinAndSelect('subCatEntries.images', 'subCatImages')
    .orderBy('category.position', 'ASC')
    .getMany();
  </code></pre>
  <p>The problem with this piece of code is that the ordering doesn't apply to the subcategories.
  Hence my question is &quot;How do I write a query that would order not only categories but also subcategories?&quot;.</p>
  <p>Thank you a lot!</p>