Prisma:如何在Prisma中获得记录的位置?
我有一个候补名单,用户通过电子邮件注册。然后,他们可以使用邀请代码并邀请更多用户。 我正在按照他们邀请的用户数量对用户进行排序。我正在排序这样:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论