Node.js 类型关系查询生成器
我在弄清楚如何使用queryBuilder从链接表中获取数据时遇到了一个小问题 目前我有以下代码:Node.js 类型关系查询生成器,node.js,postgresql,typeorm,Node.js,Postgresql,Typeorm,我在弄清楚如何使用queryBuilder从链接表中获取数据时遇到了一个小问题 目前我有以下代码: column "user.id" must appear in the GROUP BY clause or be used in an aggregate function const users=wait databasecontection .getRepository(用户) .createQueryBuilder(“用户”) .选择([“images.author\
column "user.id" must appear in the GROUP BY clause or be used in an aggregate function
const users=wait databasecontection
.getRepository(用户)
.createQueryBuilder(“用户”)
.选择([“images.author\u id”、“user.id”、“user.username”])
.LeftJoin并选择(
(queryBuilder)=>
查询生成器
。选择([“标题”、“更新位置”、“作者id”])
.来自(图像,“图像”)
.orderBy({更新地址:“ASC”})
.以(5)为例,
“图像”,
“images.author\u id=user.id”
)
.andWhere(“类似用户名:配置文件”)
.设置参数({
配置文件:`%${profile}%`,
})
.groupBy(“images.author\u id”)
.接受(限制)
.跳过(第*页限制-限制)
.getRawMany();
当前结果:
column "user.id" must appear in the GROUP BY clause or be used in an aggregate function
预期结果:
column "user.id" must appear in the GROUP BY clause or be used in an aggregate function
[
{
“id”:1,
“用户名”:“某个用户名”,
“图像”:[
{
“标题”:“一些图像标题”,
“更新时间”:“2021-05-21T03:49:44.299Z”,
“作者id”:1
}
…其余4张图片
]
}
…rest用户
]
如何使用查询生成器实现此结果
谢谢你的帮助。我不知道我的代码出了什么问题,但我被迁移到了prisma orm,他工作得和预期的一样 这里是使用prisma orm的代码,它返回预期结果(不带ID):
column "user.id" must appear in the GROUP BY clause or be used in an aggregate function
const users=wait prisma.user.findMany({
其中:{
用户名:{
包含:配置文件作为字符串,
},
},
选择:{
用户名:true,
图像:{
选择:{
标题:对,
更新地址:true,
},
订购人:{
更新地址:“asc”,
},
拍摄:5,
},
},
接受:限制,
跳过:第页*限制-限制,
});