Hi, how does Prisma handle 1-1 relationships on th...
# prisma-whats-new
m
Hi, how does Prisma handle 1-1 relationships on the User node? When I change the User Model from the authentication sample (https://github.com/graphcool/prisma/tree/master/examples/auth) to take only one post (change posts: [Post!]! to posts: Post!) I get an error when i create a new user saying i need to supply the post. What would be my strategy for a 1-1 relation like that? I cant create the post first, because it requires the user id, but i cant create the user because it needs the post. any ideas here? Or am I misunderstanding something?
m
Using the
!
on Post you made it mandatory on User. So remove the
!
m
But what if I want it to be mandatory and want to create it along with my user? Like a Status class containing a status and an emoji reference.
The same setting actually applies to any 1-1 relationshit that is mandatory. How/in what order should the objects be created?
m
is User mandatory on Post?
Create the post first with out the user id. Then create the user with the post id
m
yes, its bidirectionally mandatory
gives an error because i need to supply the user
m
I feel you're trying to do something that is atm impossible. So something will need to give.
m
Mhh you are right my approach is doomed to fail one way or the other since there is no prisma method for creating dependent objects like these. What is the recommended approach then? Remove mandatory depency on User or on Post?
m
you will need to create users before you have content (i.e. posts). So remove the mandatory flag from the User
m
thanks
However, I believe that this should be addressed somehow. If it is impossible to create 1-1 two way mandatory relationships than it should be syntactically forbidden i.e. throw an error in the deployment/code generation process. @nilan Any thoughts on this?