Answer the question
In order to leave comments, you need to log in
How to forward a top-level alias in typeorm to a subquery?
I want to forward the alias from above so as not to specify the entity to select in the subquery
let query = this.articles.createQueryBuilder('artc')
.select(['artc.title'])
.addSelect(qb => qb
.from(ArticlesEntity, 'artc')
.select('name')
.leftJoin(AuthorsEntity, 'a', 'a.id = artc.author_id')
)
let query = this.articles.createQueryBuilder('artc')
.select(['artc.title'])
.addSelect(qb => qb
.from(ArticlesEntity, 'artc1')
.select('name')
.leftJoin(AuthorsEntity, 'a', 'a.id = artc1.author_id AND artc1.id = artc.id')
)
//query = ArticlesEntity.authors(query, 'artc');
return await query.getRawMany();
Answer the question
In order to leave comments, you need to log in
working version
const query = getConnection()
.createQueryBuilder()
.select('title')
.addSelect(qb => qb
.select('name')
.from(AuthorsEntity, 'aut')
.leftJoin(ArticlesEntity, 'art1', 'aut.id = art1.author_id')
.where('art1.id = art.id'),
'name'
)
.from(ArticlesEntity, 'art');
return query.getRawMany();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question