Prisma:如何在Prisma中获得记录的位置?

发布于 2025-02-10 20:34:26 字数 718 浏览 1 评论 0原文

我有一个候补名单,用户通过电子邮件注册。然后,他们可以使用邀请代码并邀请更多用户。 我正在按照他们邀请的用户数量对用户进行排序。我正在排序这样:

const x = await prisma.user.findMany({
select: {
  id: true,
  email: true,
},
orderBy: {
  createdUsers: {
    _count: "desc",
  },
},});

这是架构:

  model User {
  id Int @id @default(autoincrement())
  createdAt DateTime @default(now())
  email  String  @unique 
  inviteCode String @unique @default(cuid())
  createdById     Int?    
  createdBy       User?       @relation("UserCreatedBy", fields: [createdById], references: [id], onDelete: NoAction, onUpdate: NoAction)
  createdUsers    User[]   @relation("UserCreatedBy")
}

我想做的基本上是根据他们邀请的用户数量告诉他们在候补名单中的位置。 有任何帮助会不胜感激吗?

I have a waitlist where users signup with their email. Then they can use their invite code and invite more users.
I am sorting users by the number of users they have invited. I am sorting like this:

const x = await prisma.user.findMany({
select: {
  id: true,
  email: true,
},
orderBy: {
  createdUsers: {
    _count: "desc",
  },
},});

This is the schema:

  model User {
  id Int @id @default(autoincrement())
  createdAt DateTime @default(now())
  email  String  @unique 
  inviteCode String @unique @default(cuid())
  createdById     Int?    
  createdBy       User?       @relation("UserCreatedBy", fields: [createdById], references: [id], onDelete: NoAction, onUpdate: NoAction)
  createdUsers    User[]   @relation("UserCreatedBy")
}

What i want to do is basically tell them the position of the user in the waitlist based on the number of users they have invited.
Any help will be appreciated?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文