Nullable relational query?
In the following, shouldn't
res.jobSeekerProfile
possibly be null? Basically what I want is to get the user - Include their jobSeekerProfile (if they have one). Currently, it seems to assume that jobSeekerProfile always exists for the user
It's telling me it's this type:
Shouldn't jobSeekerProfile be nullable?
This is the schema:
9 Replies
Try deleting the fields and references keys of the relation table and I think it should allow undefined
Oh! That did it. Not sure I understand the relations table then 😮
So when should you be defining the fields and references?
@Dan Kochetov @Andrew Sherman y’all probably should add some documentation on what fields and references means with regards to relations
It’s one of the more frequent questions being asked
you need to define the fields and relations on the opposite side
I’m sure one of us could chatGPT our way to explain the underlying typescript lol
in general, you need to define fields and references on the relation side that "knows" about both tables
i.e. the one that might have the foreign key
I know that it's not well-explained in the docs, we're working on improving those bits
@Dan Kochetov hi, is it possible to use the relations on a
nullable
field? When I try to query using with: { maybeNull: true }
, it throws an error: Cannot read properties of undefined (reading 'column's)
.
When maybeNull
isn't null, the query works.should be possible
in any case, we've designed a new API for defining relations, so some of the issues will be solved when it lands
Awesome, looking forward to it. Do you have an ETA on the release?
Sorry this is entirely my fault. The error I got wasa b/c I forgot to export the reference model. Relational queries on nullable fields are working.