TypeORM: How to order by a relation field

As of TypeORM version 0.3.0 you can do the following:

repository.find({
    order: {
        singer: {
            name: "ASC"
        }
    }
})

Before version 0.3.0 (original response)

I don’t think it is currently supported by typeorm without the query builder, there is currently a feature request open

With the QueryBuilder it is quite simple though:

connection.createQueryBuilder(Song, 'songs')
   .leftJoinAndSelect('songs.singer', 'singer')
   .orderBy('singer.name', 'ASC')
   .getMany();

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)