medz / prisma-dart

Prisma Client Dart is an auto-generated type-safe ORM. It uses Prisma Engine as the data access layer and is as consistent as possible with the Prisma Client JS/TS APIs.
https://prisma.pub
BSD 3-Clause "New" or "Revised" License
436 stars 29 forks source link

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

Closed AndryHTC closed 3 months ago

AndryHTC commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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

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