question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

default and automatic generated fields should be optional

See original GitHub issue

Hello there. Whenever I use zod to validate my schema, i validate the data coming from userland. That means any HTTP/REST API, MQTT API etc. needs to get validated in order to create or update a database entry.

That means, all fields that are autogenerated (denoted by prisma with @id) should be marked as optional or removed from the model, as they are not needed neither in create or update mechanisms.

Fields that have a default value (denoted by @default) should be optional. This could be solved by making the field itself optional with ?. However, I would like to disallow explicitly setting null, but allow implicitly accepting the default value by omitting the field. This could be solved with /// @zod.optional() in the schema, but could also be a sensible default.

What are your thoughts? Is it worth to introduce an option for the generator? Am I maybe understanding something wrong? In the end it is not so urgent, because it can be fixed on my end applying the correct types. Thanks!

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
CarterGrimmeisencommented, Feb 9, 2022

No, you are understanding it correctly. I definitely agree this needs to be incorporated in some way. I’m currently brainstorming a more all-encompassing rework that should handle this, #93, and #90. So I’ll update this issue when that becomes available! Thanks!

3reactions
davguijcommented, May 6, 2022

Hey @CarterGrimmeisen has there been any progress on this? Is this still on your radar? It would be an improvement I could surely use 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does it make sense to make a field mandatory which has a ...
If yes then it should be mandatory or else it should not. My strategy is to keep minimum fields mandatory and some sufficient...
Read more >
Set default values for fields or controls - Microsoft Support
This article explains how to set a default value for a table field or for a control on a form in an Access...
Read more >
Automatic IDs, None Defaults, and Refreshing Data - SQLModel
Now let's talk a bit about why the id field can't be NULL on the database because it's a primary key, and we...
Read more >
Specify field behavior - Atlassian Support
When Jira is installed, the Default Field Configuration is created automatically. All new projects are associated with this configuration.
Read more >
Fields - ent
All fields are required by default, and can be set to optional using the Optional method. Types​. The following types are currently supported...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found