You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Prisma中过滤关联数据?查询报错t4.id不存在

Prisma查询报错:t4.id列不存在问题解决

→ 60 const schools = await this.prisma.school.findMany(
The column t4.id does not exist in the current database.

我在使用Prisma查询数据时遇到上述错误,只有移除代码中214-216行(select.semesters.where内的subjects过滤逻辑)错误才会消失,但我需要过滤semesters,不能删除这些行。

我的查询代码如下:

const schools = await this.prisma.school.findMany({
  where: {
    semesters: {
      some: {
        isActive: true,
        subjects: {
          none: {},
        },
      },
    },
  },
  select: {
    id: true,
    name: true,
    semesters: {
      where: {
        isActive: true,
        subjects: { // line:214
          none: {}  // line:215
        }           // line:216
      },
      select: { id: true, subjects: { select: { id: true } } },
    },
  },
  take: 100,
});

我知道可以通过客户端二次处理实现需求,但更希望直接在查询阶段完成:

const schools = ...

const filteredSchools = schools.map(...).filter(...);

内容的提问来源于stack exchange,提问作者schutte

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 13:42:39