NexusPrisma-如何在全局范围内使用crud处理createdAt和updatedAt?
我想出了第一件事情,就是通过调用computedInputs的nexusPrisma选项。但它不会起作用,因为它们需要根据情况进行不同的处理,但在全局范围内:
1. create -> createdAt = now, updatedAt = null
2. update -> createdAt = keep as it is, updatedAt = now
1. create -> createdAt = now, updatedAt = null
2. update -> createdAt = keep as it is, updatedAt = now
为了使其工作,我需要像这样单独设置计算输入:
虽然这可能有效,但我无法在嵌套模型上“计算”这些输入。为了防止传递 createdAt/updatedAt,我还必须t.crud在该资源上创建另一个,没有这些时间戳。
最后一个可能有效的解决方法是根本不使用t.crud,这是一个无赖。
回答
感谢您提出问题。
Prisma 可以为您处理模型中的createdAt和updatedAt列。分别将@default(now())和@updatedAt属性添加到您的createdAt和updatedAt列中。您可以像这样将列添加到模型中:
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean? @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
您可以在我们的文档中了解更多关于@default(now())和@updatedAt`。
如果您遇到任何其他问题和疑问,我将很乐意为您提供帮助
THE END
二维码