小编Pie*_*e D的帖子

期望 orWhere() 与 andWhere() 一起使用,而不是 where()

我有一个疑问:

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 查询是:

选择不同distinctAliastopic_id作为\ “ids_topic_id \” distinctAliastopic_created_atFROM(SELECT topicidAS topic_idtopictitleAS topic_titletopiccontentAS topic_content, …

query-builder typeorm

1
推荐指数
1
解决办法
2943
查看次数

标签 统计

query-builder ×1

typeorm ×1