Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Select in finds methods optional fields #256

Closed
yovanoc opened this issue Oct 9, 2019 · 4 comments
Closed

Select in finds methods optional fields #256

yovanoc opened this issue Oct 9, 2019 · 4 comments
Assignees
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug.
Milestone

Comments

@yovanoc
Copy link

yovanoc commented Oct 9, 2019

Hello, when I select an optional field in my database like that:

select: {
    id: true,
    username: true,
    data: {
         select: {
              accountId: true
         }
    }
}

where the model is :

type CUID = String @id @default(cuid())

model AccountConfiguration {
  id                          CUID
  username           String                       @unique
  data                     AccountData?
}

then typescript definition don't tell that it can be optional (null or undefined)

image

It should be { accountId: number; } | undefined

Thanks

@pantharshit00
Copy link
Contributor

I can confirm this.
image

Reproduction: https://github.com/harshit-test-org/prisma-prisma2-696

@divyenduz divyenduz transferred this issue from prisma/prisma Oct 11, 2019
@divyenduz divyenduz added this to the Preview 15 milestone Oct 11, 2019
@divyenduz divyenduz added bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug. labels Oct 11, 2019
@timsuchanek
Copy link
Contributor

Fixed in latest alpha.
You can try it out with npm i -g prisma2@alpha.

@yovanoc
Copy link
Author

yovanoc commented Oct 14, 2019

Doesn't work for me on alpha 241, you tested it on a findOne with nested select?

@yovanoc
Copy link
Author

yovanoc commented Oct 14, 2019

Oh is working in 242, but I have a question why for an Array type it can be | null return just an empty array is better because now we have to check if its not null to iterate...

@yovanoc yovanoc mentioned this issue Oct 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug/2-confirmed We have confirmed that this is a bug. kind/bug A reported bug.
Projects
None yet
Development

No branches or pull requests

4 participants