-
Questionsuppose I have one entity, which then can have many other relations, like the Post/Tag example. Now If i'm creating a post and a tag at the same time. Can I get that specific tag I just created? is there any way to get the exact tag id created on that query? my current work around is to use two queries, which is not that bad. but wondering if i'm missing some convenience. How to reproduce (optional)No response Expected behavior (optional)No response Information about Prisma Schema, Client Queries and Environment (optional)No response |
Beta Was this translation helpful? Give feedback.
Answered by
nurul3101
Dec 10, 2025
Replies: 1 comment 2 replies
-
|
Hi @gcb! You should be able to do something like this: const post = await prisma.post.create({
data: {
title: 'new post',
tag: {
create: { label: 'new tag' },
},
},
include: {
tag: true, // include the related tag in the result
},
})
// Access the created tag and its id:
const createdTag = post.tag
const tagId = post.tag.id |
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
Ah, okay!
In that case you would need to use two separate queries which you are currently doing.