Should database tables mimic form fields?
Hey everyone, this question is not Kysely specific just wanna point that out don't know where to ask but here. I have a form for business registration that looks like this
22 Replies
However, in my database, I don't have a table that minimcs this form 1:1, I have a
user table
that looks like this and a business table
I am using the Models to create ZodSchemas so...
I can't validate the formData with a ZodSchema because it doesn't contain all those fields
I could manually create a zodSchema that has all those fields but that made me think about my question, does it make more sense to have a table that mimics my formData 1:1 + addtional fields or if that's not bad/goodUnknown User•2y ago
Message Not Public
Sign In & Join Server To View
The zod Schema is for validating form data
but it's out of sync with the actual form fields
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ya maybe I explained it bad, but it's not being input directly by user input
my zodSchemas are being auto-generated by a package that generates them based off of my Prisma schema
^ that's what my prisma schema looks like
which has a lot more fields than my form input
so my zodSchema has a lot more inputs then my form input field
so if I validate it with that zodSchema it fails
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
If you don't mind, lets use this model for an example inside my database, I have this Table.
so, the package that generates zodSchemas from my Prisma model outputs this based on the above Model but all these fields are not on my form
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
right, that's what I'm trying to do
what do you mean by resolver?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ok
ya so I'm not sure if I should adjust my Models so that I have one that atleast mimics my form input fields and all the other properties can be option
or, just manually make a zodSchema for the form input
if I do that, that gets rid of the usefulness of the zodSchema package, I guess I could delete that
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
right, the id being auto generated by the db and it's omitted from the zodSchema
in that case, it works
what's making me question things is that
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
only input field that this form contains that my Business Model doesn't is the
First & Last Name
inside my business model, I have
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
I guess for that scenario, I would just make a emailSchema
is that the right way to go about it?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ok, thank you for the help Tom!
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
😄 always