Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v4.x generates nullable attributes for non-nullable fields #353

Closed
AndryHTC opened this issue Mar 26, 2024 · 2 comments
Closed

v4.x generates nullable attributes for non-nullable fields #353

AndryHTC opened this issue Mar 26, 2024 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@AndryHTC
Copy link

I noticed that in Dart Prisma ORM version 4.x, the generated model classes have nullable attributes (?) for all fields, even when the corresponding fields in the Prisma schema are explicitly marked as non-nullable.

Is this an expected behavior in Prisma ORM 4.x? If so, what is the reasoning behind generating nullable attributes for non-nullable fields?

If this is not the intended behavior, I would appreciate any guidance on how to ensure that the generated Dart models respect the nullability constraints defined in the Prisma schema.

Thank you for your help!

@medz medz added the duplicate This issue or pull request already exists label Mar 26, 2024
@medz
Copy link
Owner

medz commented Mar 26, 2024

You should note that 4.0 supports the select and include functions. This means that the returned data fields are completely undefined. You can ask the ORM to return fields that you specify. Then other fields mean null values. So all fields being nullable is deliberate behavior.

@medz medz closed this as completed Mar 26, 2024
@medz
Copy link
Owner

medz commented Mar 26, 2024

For example prisma.user.findMany({ select: { id: true} })

means the returned data is [{id: 1}, {id: 2}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants