MySQL Relational CRUD
I am the own of issue #1395, it was closed but i don't know way to follow this suggestion: MySql doesn't support returning() you have to do it in a migration and send 2 different queries. Please create a help post in discord or a question in a discussion if you need further help.
8 Replies
My apologies, when I wrote migration I meant transaction
I'll edit the reply there
Can you show what the queries you're attempting to do look like?
I want to
create insert relation queries like prisma const userAndPosts = await prisma.user.create({
data: {
posts: {
create: [
{ title: 'Prisma Day 2020' }, // Populates authorId with user's id
{ title: 'How to write a Prisma schema' }, // Populates authorId with user's id
],
},
},
} But MySQL does''t support to returning the id of the first record. So, I do not know what to do
pplease give me example code
This is just an example. But this is the canonical way of inserting related data in Mysql
Thank you so much
This is my drizzle model
And a component
I double check your solution but the insertedId always return 0
Unfortunately, MySQL2 only gives you back the insertedId if it is an autoincrement. You have 2 options, either get the id with an extra select after the inversion, or create the id manually, storing it in a variable and use it on both insertions
please give me example code for each option
I wrote inversion, I meant insertion
Thank you
I changed my code, the insert relation has work but now I have another issue:
I want to add relation followers and following to users table ( followers and following is users ). It means i want to add self relation to users table
And update my updatedAt element, I am not certain it works