Is there any way to tell Prisma that a computed co...
# orm-help
c
Is there any way to tell Prisma that a computed column should never be passed in when creating or updating a record, but will always be present when querying the table? I'm creating a computed
fullName
column similar to this post https://github.com/prisma/prisma/discussions/8891 with the following Prisma schema (abbreviated here for clarity):
Copy code
model Employee {
  id String @id @default(uuid()) @db.Uuid
  firstName                   String
  preferredFirstName          String?
  lastName                    String
  fullName                    String?
}
I have a trigger that computes the full name based on the required first name, optional preferred first name, and required last name, so there will ALWAYS be a full name value. Trouble is, if I make
fullName
not null, then Prisma requires it to be passed in, which I don't want to do. If I make
fullName
nullable as shown above, then I can't make it required in my GraphQL schema because Prisma says it could be null, which is inaccurate because the trigger always gives it a value. Any ideas?
n
I think this is what computed fields will solve once it lands, through typescript you might be able to achieve this till the support lands. Can you have a look at this reference? https://www.prisma.io/docs/concepts/components/prisma-client/computed-fields
c
I gave up on using computed fields with Prisma, hopefully this will get added at some point.
👍 1