Comments (6)
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!
from zod-prisma.
Hey @CarterGrimmeisen has there been any progress on this? Is this still on your radar? It would be an improvement I could surely use :)
from zod-prisma.
Same issue here. I would be fine with a /// @zod.ignore
special comment to remove any specific field from the generated schema. Also, a global ignore configuration would be nice to ignore fields for the whole schema. Something like:
generator zod {
provider = "zod-prisma"
ignore = ["createdAt", "updatedAt"]
}
Would that make sense?
from zod-prisma.
In case anyone is interested I added a feature on my fork to omit any field: https://github.com/testerez/zod-prisma#omit
You can install my fork with: yarn add zod-prisma@testerez/zod-prisma
I'd be happy to open a PR here but it looks like this project is not maintained anymore.
from zod-prisma.
It doesn't make sense to me that a field could not be optional and have a default value.
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.
Why would you want to disallow null
and allow omitting the property, given than the final result will be the same (applying the default value in db) ? I fail to understand.
from zod-prisma.
I think you can forget about what I said about null
. If a field has a default value (but is not optional by nature) it should be, as convention, use the default value if omitted.
I can think of at least two scenarios where I want to use a validation schema in a basic CRUD application.
- Create - all required fields have to be required
- Update - no fields are required
Case 1 - Create
How should fields behave that are required but have a default value? Are they really required? Should I be able to configure that?
Should the validator swallow a null?
Example:
model Notification {
id Int @id @default(autoincrement())
subject String
trigger String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
createdAt
and updatedAt
are required fields as defined in the prisma schema, but they have a default value (updatedAt
has implicitly a default value, but not denoted by @default
)
prisma.notification.create({ subject: 'whatever', })
will also not complain, if you omit these fields.
However, the zod validator does.
If you create a Notification
, you wouldn't want to validate for createdAt
or updatedAt
at best it should be disallowed to be set.
Case 2 - Update
createdAt
and updatedAt
is swollowed by prisma here anyway. Not allowed to overwrite.
On update, every field should be optional. So validation errors can only happen for provided fields that are of wrong type + other limitations like min/max etc.
from zod-prisma.
Related Issues (20)
- Generated imports don't work with Typescript 4.7 module type
- Upcoming rename of `@prisma/sdk` to `@prisma/internals` with Prisma 4 HOT 2
- Optional fields should use nullable instead of nullish HOT 1
- Add support for model level definition
- Add support for connectors
- Handle composite types
- Possibility to pre-release feat/1.0-beta
- Upgrade to Prisma v4
- Support for Prisma v4 HOT 3
- Passing arguments to "z.string()" HOT 2
- new relationModel with optional relations
- More examples
- Custom Zod Schema in an Int field stills adds .int() at the end
- Is this library alive? HOT 30
- Decimal validation wrong for data loaded from database
- Impossible to `yarn remove zod` while `zod-prisma` is installed
- nullish with id autoincrement HOT 4
- Mongo DB Support
- typescript, which is a runtime dependency, is specified as a devDependency
- Bytes is `z.unknown`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zod-prisma.