我有一个疑问:
topics = await topicRepository.createQueryBuilder('topic')
.leftJoinAndSelect('topic.user', 'user', 'topic.userId = user.id')
.where('topic.categoryId = :id', {
id: categoryId,
})
.andWhere('topic.title like :search', { search: `%${searchKey}%`})
// It should take the first where
.orWhere('user.pseudo like :search', { search: `%${searchKey}%` })
.addOrderBy(filter === 'latest' ? 'topic.created_at' : 'topic.repliesCount', 'DESC')
.take(limit)
.skip(skip)
.getMany();
Run Code Online (Sandbox Code Playgroud)
生成的 SQL 查询是:
选择不同
distinctAlias。topic_id作为\ “ids_topic_id \”distinctAlias。topic_created_atFROM(SELECTtopic,idAStopic_id,topic。titleAStopic_title,topic。contentAStopic_content, …