Create and Connect query ( coming from prisma) #1796
laurent512
started this conversation in
General
Replies: 1 comment 2 replies
-
This is the canonical sql way of inserting two related records. I would just add, this should be done inside a transaction, just so that if there is an issue somewhere, nothing will get committed halfway. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone,
Migrating from prisma with limited database knowledge.
There are two entities, Adult & Pet.
Each Adult can have one or more Pet, each Pet must have an owner Adult.
In my current implementation there is a foreignkey in Pet pointing towards Adult id (pk).
I also setup a "one to many" relationship as it can be seen in the doc.
What is the right way to create in a single query a Pet and its Adult ?
Currently I am creating Adult, getting its Id in return and then creating its Pet but I assume there is a better way :)
Thank you !
Beta Was this translation helpful? Give feedback.
All reactions